login
Two 'Reverse and Add' steps are needed to reach a palindrome.
4

%I #25 Apr 13 2022 12:58:37

%S 19,28,37,39,46,48,49,57,58,64,67,73,75,76,82,84,85,91,93,94,109,119,

%T 129,139,149,150,152,153,154,159,160,162,163,169,170,172,173,179,189,

%U 208,218,219,228,229,238,239,248,250,251,253,258,259,260,261,268,269

%N Two 'Reverse and Add' steps are needed to reach a palindrome.

%C The number of steps starts at 0, so palindromes (cf. A002113) are excluded.

%H Michael S. Branicky, <a href="/A065207/b065207.txt">Table of n, a(n) for n = 1..10000</a> (terms 1..1000 from Harry J. Smith)

%H <a href="/index/Res#RAA">Index entries for sequences related to Reverse and Add!</a>

%t trasQ[n_]:=Length[NestWhileList[IntegerReverse[#]+#&,n,!PalindromeQ[ #]&,1,5]] ==3; Select[Range[300],trasQ] (* _Harvey P. Dale_, Apr 13 2022 *)

%o (ARIBAS): revadd_steps(2,58). For the definition of function revadd_steps see A065206.

%o (PARI)

%o Rev(x)= { local(d, r=0); while (x>0, d=x-10*(x\10); x\=10; r=r*10 + d); return(r) }

%o digitsIn(x)= { local(d); if (x==0, return(1)); d=1 + log(x)\log(10); if (10^d == x, d++, if (10^(d-1) > x, d--)); return(d) }

%o Palin(x)= { local(d,e,f,i,t,y); if (x==0, return(1)); y=x; d=digitsIn(x); t=10^(d - 1); for (i=1, d\2, f=y-10*(y\10); y\=10; e=x\t; x-=t*e; t/=10; if (e!=f, return(0)) ); return(1) }

%o { n=0; for (m = 0, 10^9, p=m; b=1; for (i=1, 2, if (Palin(p), b=0; break); p=Rev(p) + p); if (b && Palin(p), write("b065207.txt", n++, " ", m); if (n==1000, return)) ) } \\ _Harry J. Smith_, Oct 14 2009

%o (Python)

%o def ra(n): s = str(n); return int(s) + int(s[::-1])

%o def ispal(n): s = str(n); return s == s[::-1]

%o def aupto(limit):

%o alst = []

%o for k in range(limit+1):

%o if ispal(k): continue

%o k2 = ra(k)

%o if ispal(k2): continue

%o if ispal(ra(k2)): alst.append(k)

%o return alst

%o print(aupto(269)) # _Michael S. Branicky_, May 06 2021

%Y Cf. A002113, A015977, A065206.

%K nonn,base

%O 1,1

%A _Klaus Brockhaus_, Oct 21 2001

%E Offset changed from 0 to 1 by _Harry J. Smith_, Oct 14 2009