OFFSET
0,9
EXAMPLE
5 -> 10 -> 5 -> ..., so 5 is already in a cycle and a(5) = 0. 13 -> 44 -> 22 -> 11 -> 22 -> ..., so a(13) = 2.
MATHEMATICA
Step[n_] := If[ EvenQ[n], n/2, n + FromDigits[ Reverse[ IntegerDigits[n]]]]; cPalHash = 1013; clearArray = Array[{} &, cPalHash]; InsertCheck[n_, a_] := Module[{i = Mod[n, cPalHash] + 1}, a[[i]] = Append[a[[i]], n]]; SetAttributes[ InsertCheck, HoldRest]; CheckArray[n_, a_] := MemberQ[ a[[Mod[n, cPalHash] + 1]], n]; SetAttributes[ CheckArray, HoldRest]; PalListHelper[n_, cTries_] := Module[{ch = clearArray}, NestWhileList[ (InsertCheck[ #, ch]; Step[ # ]) &, n, Not[ CheckArray[ #, ch]] &, 1, cTries]]; PalList[n_, cTries_] := Module[{lst, nRemoved, loop}, lst = PalListHelper[n, cTries]; nRemoved = First[ First[ Position[lst, lst[[ -1]]]]]; loop = Drop[ Take[lst, {nRemoved, -1}], -1]; Append[ Take[lst, {1, nRemoved - 1}], loop]]; Table[ Length[ PalList[n, 1013]] - 1, {n, 0, 104}] (from Darrell Plank (jar_czar(AT)msn.com), Dec 28 2003)
CROSSREFS
KEYWORD
nonn,base,easy
AUTHOR
N. J. A. Sloane, Jan 01 2004
EXTENSIONS
More terms from John W. Layman and Robert G. Wilson v, Jan 05 2004
STATUS
approved