|
|
A151963
|
|
(Length of preperiodic part) + (length of cycle) of trajectory of n under iteration of the Kaprekar map in A151949.
|
|
10
|
|
|
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
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
0,2
|
|
COMMENTS
|
Equals A151962(n) + 1 iff n < 10001 (when a cycle of length greater than 1 occurs for the first time).
|
|
LINKS
|
|
|
EXAMPLE
|
13->18->63->27->45->9->0->0, so a(13)=6+1 = 7.
|
|
MAPLE
|
local tup;
tup := sort(convert(n, base, 10)) ;
add( (op(i, tup)-op(-i, tup)) *10^(i-1), i=1..nops(tup)) :
end:
local tra, x ;
tra := [n] ;
x := n ;
while true do
if x in tra then
RETURN(nops(tra)) ;
fi;
tra := [op(tra), x] :
od:
end:
|
|
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 *)
|
|
CROSSREFS
|
|
|
KEYWORD
|
nonn,base
|
|
AUTHOR
|
|
|
EXTENSIONS
|
|
|
STATUS
|
approved
|
|
|
|