A151962 Length of preperiodic part of trajectory of n under iteration of the Kaprekar map in A151949.
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 6, 4, 5, 3, 3, 5, 4, 6, 2, 1, 2, 6, 4, 5, 3, 3, 5, 4, 6, 2, 1, 2, 6, 4, 5, 3, 3, 5, 4, 6, 2, 1, 2, 6, 4, 5, 3, 3, 5, 4, 6, 2, 1, 2, 6, 4, 5, 3, 3, 5, 4, 6, 2, 1, 2, 6, 4, 5, 3, 3, 5, 4, 6, 2, 1, 2, 6, 4, 5, 3, 3, 5, 4, 6, 2, 1, 2, 6, 4, 5, 3, 3, 5, 4, 6, 2
Offset: 0
Examples
13 -> 18 -> 63 -> 27 -> 45 -> 9 -> 0 -> 0, so a(13)=6.
Links
Crossrefs
Programs
-
Maple
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: A151962 := proc(n) local tra,x ; tra := [n] ; x := n ; while true do x := A151949(x) ; if member(x,tra,'l') then RETURN(l-1) ; fi; tra := [op(tra),x] : od: end: seq(A151962(n),n=0..120) ; # R. J. Mathar, Aug 20 2009
Extensions
More terms from R. J. Mathar, Aug 20 2009