Unhappy Number

Author

Eric W. Weisstein
March 27, 2006

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

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

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

Code

HappyList[n_]:=NestWhileList[Total[IntegerDigits[#]^2]&,n,UnsameQ,All]
HappyNumber[n_]:=NestWhile[Total[IntegerDigits[#]^2]&,n,UnsameQ,All]
HappyQ[n_]:=HappyNumber[n]==1

Enumeration

Select[Range[100],!HappyQ[#]&]