Is it easy to prove that for any $n$, $f^k(n)= 4$ for some $k$ or $f^k(n)= 1$ for some $k$ holds? (Mathematica book by Roozbeh Hazrat)

40 Views Asked by At

I am reading "Mathematica: A Problem-Centered Approach Second Edition" by Roozbeh Hazrat.

The following problem is Problem 8.13 on p. 137:

A happy number is a number such that if one squares its digits and adds them together, and then takes the result and squares its digits and adds them together again and keeps doing this process, one comes down to the number $1$. Find all the happy ages, i.e., happy numbers up to $100$.

The author's answer is the following:

Select[Range[100], NestWhile[Plus @@ (IntegerDigits[#]^2)&, #, (!#==4) && (!#==1)&] == 1&]


Let $f$ be the following function:
f[n_] := Apply[Plus, IntegerDigits[n]^2];

The author assumes that for any $n$, $f^k(n)= 4$ for some $k$ or $f^k(n)= 1$ for some $k$ holds.
But the author didn't write that this property holds in the above book.
I wonder why the author didn't write that this property holds.

Is it easy to prove that for any $n$, $f^k(n)= 4$ for some $k$ or $f^k(n)= 1$ for some $k$ holds?

I checked the following holds:
$f(4)=16\neq 1, f(16)=37\neq 1, f(37)=58\neq 1, f(58)=89\neq 1, f(89)=145\neq 1, f(145)=42\neq 1, f(42)=20\neq 1, f(20)=4.$
And obviously $f(1)=1$.

If you know a proof of the above property, please tell me the proof.

1

There are 1 best solutions below

0
On

Martin R, Thank you very much for your link.

I checked if $1\leq n\leq 279$, then $f^k(n)=4$ for some $k$ or $f^k(n)=1$ for some $k$ holds:

Input:
f[n_] := Apply[Plus, IntegerDigits[n]^2];
g[n_] := !((n == 1) || (n == 4));
h[n_] := NestWhile[f, n, g];
Map[h, Range[279]]

The above code terminated.