A345112 a(n) is the number of steps to reach a palindrome > n under repeated applications of the map x -> A345111(x) starting with n, or 0 if no palindrome is ever reached.
1, 1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 19, 1, 1, 1, 1, 1, 1, 3, 1, 19
Offset: 1
Examples
For n = 39: The trajectory of 39 under the given map starts 39, 132, 453, 987, 1866, 10527, 15798, 73779, 111576, 227337, 500709, 507804, 585849, 1444344, 5887785, 14765640, 62422041, 86642457, 153067035, 683737386, reaching the palindrome 683737386 after 19 iterations, so a(39) = 19.
Programs
-
PARI
eva(n) = subst(Pol(n), x, 10) rot(vec) = if(#vec < 2, return(vec)); my(s=concat(Str(2), ".."), v=[]); s=concat(s, Str(#vec)); v=vecextract(vec, s); v=concat(v, vec[1]); v a(n) = my(x=n, i=0); while(1, x=x+eva(rot(digits(x))); i++; if(digits(x)==Vecrev(digits(x)), break)); i
-
Python
def pal(s): return s == s[::-1] def rotl(s): return s[1:] + s[0] def A345111(n): return n + int(rotl(str(n))) def a(n): i, iter, seen = 0, n, set() while not (iter > n and pal(str(iter))) and iter not in seen: seen.add(iter) i, iter = i+1, A345111(iter) return i if iter > n and pal(str(iter)) else 0 print([a(n) for n in range(1, 49)]) # Michael S. Branicky, Jun 09 2021
Comments