A117831 Let S_n be the infinite sequence formed by starting with n and repeatedly reversing the digits and adding 4 to get the next term. Sequence gives number of steps for S_n to reach a cycle, or -1 if no cycle is ever reached.
1, 1, 40, 7, 0, 0, 39, 6, 0, 0, 38, 5, 0, 18, 37, 3, 0, 43, 10, 0, 4, 42, 9, 4, 4, 41, 7, 0, 47, 40, 0, 8, 46, 13, 0, 8, 45, 11, 0, 7, 44, 0, 12, 50, 17, 3, 12, 49, 15, 1, 11, 48, 1, 16, 36, 3, 0, 16, 35, 1, 0, 41, 8, 2, 2, 40, 7, 2, 2, 39, 5, 0, 45, 12, 0, 6, 44, 11, 0, 6, 43, 9, 0, 49, 42, 0, 10
Offset: 1
Links
- Robert Israel, Table of n, a(n) for n = 1..10000
- N. J. A. Sloane and others, Sequences of RADD type, OEIS wiki.
Crossrefs
Programs
-
Maple
V:= Vector(10^5,-1): f:= proc(n) local L, H, S, i, j,found,x,y; global V; S:= {n}: H:= n; x:= n; for i from 1 to 10^5 do if V[x] > -1 then for j from 1 to i-1 do V[H[j]]:= i-j+V[x] od; return V[n]; fi; L:= convert(x,base,10); x:= add(L[-j]*10^(j-1),j=1..nops(L)) + 4; if member(x, S) then found:= false; y:= 0; V[x]:= 0; for j from i by -1 to 1 do if H[j] = x then found:= true elif not found then V[H[j]]:= 0 else y:= y+1; V[H[j]]:= y; fi od; return V[n] fi; H:= H, x; S:= S union {x}; od; end proc: map(f, [$1..200]); # Robert Israel, May 07 2020
Extensions
Corrected and extended by Klaus Brockhaus, May 05 2006
Confirmed by N. J. A. Sloane, May 05 2006
Comments