cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A329267 a(n) is the absolute difference between n and its nearest palindromic neighbor.

Original entry on oeis.org

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

Views

Author

Christopher J. Shore, Nov 09 2019

Keywords

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?"

Examples

			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
		

Crossrefs

Programs

  • 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 *)
  • 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