# what loops and points of numbers are possible when you take the alternating sum of the digits of squared?

what loops of numbers are possible when you take the alternating sum of the digits of squared? I've heard about the happy numbers and the sad numbers. if you don't know the happy numbers are numbers when you add it's digits$$^2$$ and do that n times it hits the floor value of $$1$$. sad numbers are numbers that go into the same endless loop of sadness $$(20,4,16,37,58,89,145,42,20,...)$$ $$(\space2^2+1^2=4,\space4^2=16,\space1^2+6^2=37,\space3^2+7^2=58,\space5^2+8^2=89,\space8^2+9^2=145,\space1^2+4^2+5^2=42,\space4^2+2^2=20)$$

my question is slightly different instead of the sum mine uses the absolute value of the alternating sum. so far I've found $$2$$ loops and to $$2$$ points $$(\space9^2=81,\space8^2-1^2=63,\space6^2-3^2=27,\space|2^2-7^2|=45,\space|4^2-5^2|=9,\dots),(\space|1^2-6^2|=35,\space|3^2-5^2|=16)$$ $$the\space points\space are\space0\space and\space 1 \space . 1^2-0^2=1,1^2-1^2=0$$ doing this with a $$3$$ digit number looks like this you start with $$125$$ do this$$|1^2-2^2+5^2|=23$$ and you get $$22$$.

My question is how many points and loops are there are?

Partial answer: the only points are $$0,1$$ and $$48$$.

Let $$f()$$ be the function that performs one step of your transformation, e.g. $$f(125) = |1^2 - 2^2 + 5^2| = 22$$ (not $$23$$ like you said).

If $$x$$ is a $$k$$-digit number, we have $$f(x) \le \lceil k/2 \rceil \times 9^2$$ because half the digits count positively and half count negatively, and each digit is at most $$9$$. This bound immediately shows that $$f(x) < x$$ for these cases ($$d$$ denotes leading digit):

• All $$k \ge 4$$.

• $$k = 3, d \ge 2: f(x) \le 2 \times 81$$ but $$x \ge 200$$.

• $$k = 3, d = 1:$$ let the number be $$x = (1bc)_{10}$$ and $$f(x) = |1 - b^2 + c^2| \le 1 + 81$$ but $$x \ge 100$$.

Now consider $$k=2, x = (ab)_{10} = 10a + b$$.

• If $$a \ge b$$, we have $$f(x) \le a^2 < 10a \le x$$.

• If $$a < b$$, for $$x$$ to be a point we need $$f(x) = b^2 - a^2 = 10a + b$$ or $$b(b-1) = (10+a)a.$$ Now it is just a matter of trying each $$a = 1, 2, 3, \dots$$ and we find that the only solution is $$x = 48, a = 4, b = 8:$$

$$f(48) = |4^2 - 8^2| = 64 - 16 = 48$$

For $$k=1$$ we have $$f(x) = x^2$$ so $$f(x) = x$$ iff $$x = 0,1$$.

Incidentally, since $$f(x) < x$$ for sufficiently large $$x$$, this also means the process "collapses" onto the small integers, and there are only a finite number of loops.