```Hans Fugal wrote:

/ ...

>> As I understand the Wolfram article, an unhappy number never hits 1 as a
>> result, whereas a happy number eventually hits 1:
>
> What you have described here is the halting problem. Good luck with that.

Possibly, I haven't thought it through. I can't find any numbers that fail
to get to either 1 or 4 in a short time. Doesn't mean they aren't out
there.

>> "Unhappy numbers have eventually periodic sequences of s(sub)i which
>> never reach 1."
>
> And what stops it from being a 1x10^50 length period, or any arbitrary
> length?

As the algorithm proceeds, the length of the numbers tends to decline, until
it reaches one of 0,1, or 4. The first two are dead ends, the third cycles
a short loop forever, such that it is adequate to detect one of [ 0,1,4 ]
as a halting criterion.

>> The quiz item emphasizes a criterion that is only mentioned in passing on
>> the Wolfram page, that is, there are degrees of happiness, and a number
>> that has many happy predecessors is, umm, more happy. So a relatively
>> large number that eventually results in 1, but with a lot of steps along
>> the way (therefore more happy ancestors), is happier.
>
> And what the quiz neglected to mention is that there is an easy test for
> unhappy number, which the mathworld page enumerates:
>
> Iterating this sum-of-squared-digits map always eventually
> reaches one of the 10 numbers 0, 1, 4, 16, 20, 37, 42, 58, 89,
> or 145 (Sloane's A039943; Porges 1945).
>
> So if you hit one of those unhappy numbers you know you're in an unhappy
> loop.

My relatively unsophisticated program simply loops and halts on reaching 0,1
or 4.

--
Paul Lutus
http://www.arachnoid.com

```