I'm trying to find "happy / sad numbers", that means you take the squares of the digits of your number and add them together, then you repeat this over and over again; at the end, you'll either get 1 or a repeating cycle with 4. I also want to know, how many times you have to do this to get to the number 1 or into the cycle 4 (in my code, I just want to get either the number 1 or 4 to end the calculations):
Do[For[i = 0, x != 1 && x != 4, x = ((x - mod[x, 10])/10)^2 + (mod[x, 10])^2, i++]; Print[{i, x}], {x, 99}]
My thoughts: I want to do this with x from 1 to 99 (the equation in the middle can only handle these numbers; I'll insert another one afterwards). "i" is here to count the number of calculations. In the For-loop is the test whether x is 1 or 4, so it has to stop, or x is allowed to get a new value. When it leaves, it prints out the number of calculations and the end-number. But the output looks like this:
{0,1}
{1,1/100 (2-mod[2,10])^2+mod[2,10]^2}
{1,1/100 (3-mod[3,10])^2+mod[3,10]^2}
{0,4}
{1,1/100 (5-mod[5,10])^2+mod[5,10]^2}
etc.
I'm not familiar with the Wolfram Language because I am really new here. I would be pleased if you could please tell me why this happend and how I could prevent such mistakes.