login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 


A262040
Nearest palindrome to n; in case of a tie choose the smaller palindrome.
2
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 11, 11, 11, 11, 11, 11, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 77, 77
OFFSET
0,3
COMMENTS
In contrast to A262039, here we "round down" to the next smaller palindrome A261423(n) if it is at the same distance or closer, else we "round up" to the next larger palindrome A262038(n).
EXAMPLE
a(10) = 9 since we round down if the next larger palindrome (here 11) is at the same distance, both 9 and 11 are here at distance 1 from n = 10.
a(16) = 11 since |16 - 11| = 5 is smaller than |16 - 22| = 6.
a(17) = 22 since |17 - 22| = 5 is smaller than |17 - 11| = 6.
a(27) = 22 since |22 - 27| = 5 is smaller than |27 - 33| = 6.
a(28) = 33 since |33 - 28| = 5 is smaller than |22 - 28| = 6, and so on.
a(100) = 99 because we round down in this case, where 99 and 101 both are at distance 1 from n = 100.
MATHEMATICA
palQ[n_] := Block[{d = IntegerDigits@ n}, d == Reverse@ d];
f[n_] := Block[{k = n}, While[Nand[palQ@ k, k > -1], k--]; k];
g[n_] := Block[{k = n}, While[! palQ@ k, k++]; k];
h[n_] := Block[{a = f@ n, b = g@ n}, Which[palQ@ n, n, (b - n) - (n - a) >= 0, a, (b - n) - (n - a) < 0, b]]; Table[h@ n, {n, 0, 73}] (* Michael De Vlieger, Sep 09 2015 *)
CROSSREFS
KEYWORD
nonn,base
AUTHOR
M. F. Hasler, Sep 08 2015
STATUS
approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified September 23 08:07 EDT 2024. Contains 376143 sequences. (Running on oeis4.)