login
A329267
a(n) is the absolute difference between n and its nearest palindromic neighbor.
0
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 5, 4, 3, 2
OFFSET
0,14
COMMENTS
Empirical observation: this sequence is similar to A261424 but yields the absolute difference between n and its nearest palindromic neighbor. It answers the question "How far from this number is the nearest palindrome?"
EXAMPLE
For 0 <= n <= 9, n is palindromic so a(n) = 0.
a(10) = 10-9 = 11-10 = 1 (10 is equidistant from its two nearest palindromes).
a(11) = 0 because 11 is palindromic.
For 12 <= n <= 16, a(n) = n-11 because 11 is the nearest palindromic number.
For 17 <= n <= 22, a(n) = 22-n because 22 is the nearest palindromic number.
.
n nearest palindrome difference
-- ------------------ ----------
1 1 1-1 = 0
2 2 2-2 = 0
3 3 3-3 = 0
4 4 4-4 = 0
5 5 5-5 = 0
6 6 6-6 = 0
7 7 7-7 = 0
8 8 8-8 = 0
9 9 9-9 = 0
10 9 or 11 10-9 = 11-10 = 1
11 11 11-11 = 0
12 11 12-11 = 1
13 11 13-11 = 2
14 11 14-11 = 3
15 11 15-11 = 4
16 11 16-11 = 5
17 22 22-17 = 5
18 22 22-18 = 4
19 22 22-19 = 3
20 22 22-20 = 2
21 22 22-21 = 1
22 22 22-22 = 0
23 22 23-22 = 1
MATHEMATICA
palQ[n_] := Block[{d = IntegerDigits[n]}, d == Reverse@ d]; a[n_] := Block[{k=0}, While[! palQ[n+k] && ! palQ[n-k], k++]; k]; Array[a, 121] (* Giovanni Resta, Nov 12 2019 *)
PROG
(PARI) ispal(n) = my (d=digits(n)); d==Vecrev(d)
a(n) = for (k=0, oo, if (ispal(n-k) || ispal(n+k), return (k))) \\ Rémy Sigrist, Dec 03 2019
CROSSREFS
Sequence in context: A373798 A101916 A361979 * A100771 A234470 A113771
KEYWORD
nonn,base
AUTHOR
STATUS
approved