Problem :
A Happy number is a number that if one squares its digits and add them together, and then take the result and square its digits and add them together again and keep doing this process, one comes down to the number 1. Find all the Happy ages, i.e., happy numbers up to 100.
This is the problem the book gave, and the solution of the author is shown below:
f[1] = 1;
f[4] = 4;
f[n_] := f[Plus @@ ( IntegerDigits[n]^2)]
Select[Range[100], f[#] == 1 &]
(*
{1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100}
*)
But I want to use a different method from the author.
Select[Range[100], NestWhile[Plus @@ (IntegerDigits[#]^2 &), # &, # != 1 &]]
(*{}*)
However, I do not know where it went wrong. Could someone help me? Thanks!