RATS Sequence

Author

Eric W. Weisstein
December 19, 2005

This notebook downloaded from http://mathworld.wolfram.com/notebooks/IntegerSequences/RATSSequence.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/RATSSequence.html.

©2005 Wolfram Research, Inc. except for portions noted otherwise

Code

RATS[n_,its_:100]:=NestWhileList[FromDigits[Sort[IntegerDigits[#+FromDigits[Reverse[IntegerDigits[#]]]]]]&,n,UnsameQ,All,its]
RATSPeriod[l_List,its_:100]:=If[Length[l]>its,0,Length[l]-Position[Most[l],Last[l],1,1][[1,1]]]

Enumeration

RATS[1,20]

RATSPeriod[%,20]

Periods

Take[(per=Table[RATSPeriod[RATS[n,100]],{n,10^5}]),20]//Timing

Take[(per=Table[RATSPeriod[RATS[n]],{n,10^6}]),100]//Timing

Union[per]

Take[(per=Table[RATSPeriod[RATS[n,50],50],{n,10^7}]),100]//Timing

Union[per]

Take[(per=Table[RATSPeriod[RATS[n,50],50],{n,5 10^7}]),100]//Timing

Union[per]

{#,Position[per,#,1,15]//Flatten}&/@Union[per]//ColumnForm