Sort Then Add Sequence

Author

Eric W. Weisstein
April 27, 2002

This notebook downloaded from http://mathworld.wolfram.com/notebooks/IntegerSequences/Sort-Then-AddSequence.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/Sort-Then-AddSequence.html.

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

Initialization

<<EISFormat`

Sort then add

SortThenAdd[n_,b_:10]:=n+FromDigits[Sort[IntegerDigits[n,b]],b]

FormatSequence[
Table[SortThenAdd[n],{n,100}],
70196,1,
Name->"a(n)=n plus the sorted version of the base-10 digits of n.",
Cross->{33862},
html["Sort-Then-Add Sequence"]
]

Sort then add until sorted

SortThenAddUntilSorted[n_Integer?Positive,b_:10]:=n/;OrderedQ[IntegerDigits[n,b]]

SortThenAddUntilSortedList[n_Integer?Positive,b_:10]:=FixedPointList[#+FromDigits[Sort[IntegerDigits[#,b]],b]&,n,Infinity,SameTest->(OrderedQ[IntegerDigits[#2,b]]&)]

SortThenAddUntilSorted[n_,b_:10]:=FixedPoint[#+FromDigits[Sort[IntegerDigits[#,b]],b]&,n,Infinity,SameTest->(OrderedQ[IntegerDigits[#2,b]]&)]

Table[SortThenAddUntilSorted[n],{n,20}]