Digitaddition

Author

Eric W. Weisstein
February 2, 2005

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

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

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

Code

DigitadditionSequence[k_,n_]:=NestWhileList[Plus@@(IntegerDigits[#]^k)&,n,UnsameQ,All]
DigitadditionStartOfPeriod[k_,n_]:=NestWhile[Plus@@(IntegerDigits[#]^k)&,n,UnsameQ,All]

k==1 (Digital Roots)

(l=DigitadditionSequence[1,#]&/@Range[20])//ColumnForm

Digital Roots

DigitadditionStartOfPeriod[1,#]&/@Range[20]

k==2

Take[l=DigitadditionSequence[2,#]&/@Range[100],10]//ColumnForm

DigitadditionStartOfPeriod[2,#]&/@Range[20]

Happy Numbers

Position[Flatten[-Subtract@@@(Position[#,Last[#]]&/@l)],1]//Flatten