A151963 (Length of preperiodic part) + (length of cycle) of trajectory of n under iteration of the Kaprekar map in A151949.
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 3, 7, 5, 6, 4, 4, 6, 5, 7, 3, 2, 3, 7, 5, 6, 4, 4, 6, 5, 7, 3, 2, 3, 7, 5, 6, 4, 4, 6, 5, 7, 3, 2, 3, 7, 5, 6, 4, 4, 6, 5, 7, 3, 2, 3, 7, 5, 6, 4, 4, 6, 5, 7, 3, 2, 3, 7, 5, 6, 4, 4, 6, 5, 7, 3, 2, 3, 7, 5, 6, 4, 4, 6, 5, 7, 3, 2, 3, 7, 5, 6, 4, 4, 6, 5, 7, 3
Offset: 0
Examples
13->18->63->27->45->9->0->0, so a(13)=6+1 = 7.
Links
- Joseph Myers and Robert G. Wilson v, Table of n, a(n) for n = 0..1000 .
- Index entries for the Kaprekar map
Crossrefs
Programs
-
Maple
# Maple program from R. J. Mathar: A151949 := proc(n) local tup; tup := sort(convert(n,base,10)) ; add( (op(i,tup)-op(-i,tup)) *10^(i-1),i=1..nops(tup)) : end: A151963 := proc(n) local tra,x ; tra := [n] ; x := n ; while true do x := A151949(x) ; if x in tra then RETURN(nops(tra)) ; fi; tra := [op(tra),x] : od: end: seq(A151963(n),n=0..120) ;
-
Mathematica
f[n_] := Module[{idn = IntegerDigits@n, idns}, idns = Sort@ idn; FromDigits@ Reverse@ idns - FromDigits@ idns]; g[n_] := Length[ NestWhileList[ f, n, UnsameQ, All]] - 1; Table[g@n, {n, 0, 104}] (* Robert G. Wilson v, Aug 20 2009 *)
Extensions
Typos corrected by Joseph Myers, Aug 20 2009
More terms from R. J. Mathar and Robert G. Wilson v, Aug 20 2009
Comments