A016016 Number of iterations of Reverse and Add which lead to a palindrome, or -1 if no palindrome is ever reached.
1, 1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, 2, 1, 1, 1, 1, 1, 2, 1, 2, 2, 3, 1, 1, 1, 1, 2, 1, 2, 2, 3, 4, 1, 1, 1, 2, 1, 2, 2, 3, 4, 6, 1, 1, 2, 1, 2, 2, 3, 4, 6, 24, 1, 2, 1, 2, 2, 3, 4, 6, 24
Offset: 1
Examples
6 -> 6 + 6 = 12 -> 12 + 21 = 33 is palindromic, took 2 steps so a(6)=2. n = 89 needs 24 steps to end up with the palindrome 8813200023188. See A240510. - _Wolfdieter Lang_, Jan 12 2018
Links
- T. D. Noe, Table of n, a(n) for n = 1..195
- J. Walker, Three Years Of Computing: Final Report On The Palindrome Quest
- Eric Weisstein's World of Mathematics, 196-Algorithm.
- Index entries for sequences related to Reverse and Add!
Programs
-
Mathematica
tol = 1000; r[n_] := FromDigits[Reverse[IntegerDigits[n]]]; palQ[n_] := n == r[n]; ar[n_] := n + r[n]; Table[k = 0; If[palQ[n], n = ar[n]; k = 1]; While[! palQ[n] && k < tol, n = ar[n]; k++]; If[k == tol, k = -1]; k, {n, 98}] (* Jayanta Basu, Jul 11 2013 *) With[{nn = 10^3}, Array[-1 + Length@ NestWhileList[# + IntegerReverse@ # &, #, ! PalindromeQ@ # &, {2, 1}, 10^3] /. k_ /; k == nn -> -1 &, 200, 0]] (* Michael De Vlieger, Jan 11 2018 *)
-
PARI
a(n) = my(x=n, i=0); while(1, x=x+eval(concat(Vecrev(Str(x)))); i++; if(x==eval(concat(Vecrev(Str(x)))), return(i))) \\ Felix Fröhlich, Jan 12 2018
-
PARI
A016016(n, LIM=exponent(n+1)*5)={-!for(i=0, LIM, my(r=A004086(n)); n==r&&i&&return(i); n+=r)} \\ with {A004086(n)=fromdigits(Vecrev(digits(n)))}. The second optional arg is a search limit, with default value chosen according to known records A065199 and indices A065198. - M. F. Hasler, Feb 16 2020
Comments