Happy Numbers
Vasiliki Liontou 22/12/17
Let n be an integer. If we sum the squares of its digits in base-ten, and we replace the number with that sum, after finite repetitions we either get back the same number n or 1. If we get 1 the integer n is a happy number.

(*The function HappyNumber takes an integer as input and gives all the happy numbers from 1 up to that integer*)

HappyNumber[c_Integer]:=For[i=1,i≤c,i++,
sum=0;
number=i;
While[number≠0,
tmp=Mod[number,10];
sum=sum+(tmp*tmp);
number=(number-tmp)/10;
If[number==0,
If[sum==1,Print[i];Break[];];
If[sum==4||sum==89||sum==145||sum==42||sum==62||sum==16||sum==37||sum==58||sum==89,Break[]];
number=sum;
sum=0]]]

HappyNumber[100]

HappyNumber[1000]

HappyNumber[10000]