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.

A241173 Start with n; add to it any of its digits; repeat; a(n) = minimal number of steps needed to reach a palindrome.

This page as a plain text file.
%I A241173 #40 Oct 11 2024 16:11:06
%S A241173 0,0,0,0,0,0,0,0,0,0,1,0,3,2,3,2,1,4,3,2,1,1,0,3,3,2,3,3,2,4,1,3,3,0,
%T A241173 2,2,2,1,3,2,1,2,1,3,0,2,2,3,4,2,1,4,3,2,2,0,4,3,1,3,1,4,3,1,2,2,0,3,
%U A241173 4,3,1,3,2,2,4,2,3,0,3,1,1,3,2,3,1,2,2,3,0,5,1,2,1,4,5,2,3,4,5,0
%N A241173 Start with n; add to it any of its digits; repeat; a(n) = minimal number of steps needed to reach a palindrome.
%C A241173 a(n) = 0 iff n is already a palindrome (A002113).
%C A241173 Is it a theorem that a(n) always exists?
%C A241173 a(n) always exists. Proof: A palindrome can be reached by simply adding the initial digit until a palindrome with the same number of digits as the initial number is reached: If no palindrome is reached by then, this will yield a number with initial digit '1'. Thereafter, this procedure will yield the next larger palindrome - either not larger than 19...91 or, after 19...9 + 1 = 20...0, at 20...02. - _M. F. Hasler_, Apr 26 2014
%D A241173 Eric Angelini, Posting to Sequence Fans Mailing List, Apr 20 2014
%H A241173 David A. Corneth, <a href="/A241173/b241173.txt">Table of n, a(n) for n = 0..9999</a>
%H A241173 David A. Corneth, <a href="/A241173/a241173_1.gp.txt">PARI program</a>
%H A241173 David A. Corneth, <a href="/A241173/a241173.gp.txt">Steps taken from n as described in name to reach a palindrome</a>
%e A241173 Examples for a(10) through a(23):
%e A241173 a(10) = 1 via 10 -> 11
%e A241173 a(11) = 0 via 11
%e A241173 a(12) = 3 via 12 -> 13 -> 16 -> 22
%e A241173 a(13) = 2 via 13 -> 16 -> 22
%e A241173 a(14) = 3 via 14 -> 15 -> 16 -> 22
%e A241173 a(15) = 2 via 15 -> 16 -> 22
%e A241173 a(16) = 1 via 16 -> 22
%e A241173 a(17) = 4 via 17 -> 18 -> 19 -> 20 -> 22
%e A241173 a(18) = 3 via 18 -> 19 -> 20 -> 22
%e A241173 a(19) = 2 via 19 -> 20 -> 22
%e A241173 a(20) = 1 via 20 -> 22
%e A241173 a(21) = 1 via 21 -> 22
%e A241173 a(22) = 0 via 22
%e A241173 a(23) = 3 via 23 -> 25 -> 30 -> 33
%t A241173 A241173[n_] := Module[{c, nx},
%t A241173    If[n == IntegerReverse[n], Return[0]];
%t A241173    c = 1; nx = n;
%t A241173    While[ ! AnyTrue[nx = Flatten[nx + IntegerDigits[nx]], # == IntegerReverse[#] &], c++];
%t A241173    Return[c]];
%t A241173 Table[A241173[i], {i, 0, 100}] (* _Robert Price_, Mar 17 2019 *)
%o A241173 (PARI) a(n,m=0)={ if( m, my(d); for(i=1,#d=vecsort(digits(n),,12), d[i] && if( m>1, a(n+d[i],m-1) /*&& !print1("/*",[n,d[i],m],"* /")*/, is_A002113(n+d[i])) && return(m)), is_A002113(n) || until(a(n,m++),); m)} \\ Memoization should be implemented to improve performance which remains poor esp. for terms just above 10^k+1. - _M. F. Hasler_, Apr 26 2014
%o A241173 (PARI) \\ See Corneth link; faster than above. _David A. Corneth_, Mar 21 2019
%Y A241173 Cf. A002113.
%Y A241173 A241174 gives the smallest number that takes n steps to reach a palindrome.
%Y A241173 Related sequences: A241173, A241174, A241175, A241176, A241177, A241178, A241179, A241180, A241181, A241182, A241183.
%K A241173 nonn,base
%O A241173 0,13
%A A241173 _N. J. A. Sloane_, Apr 23 2014
%E A241173 More terms from _M. F. Hasler_, Apr 26 2014