Happy number

Math

A happy number is a number that goes through this process of squaring its own digits, finishing until you get 1.

Some numbers will not end up with 1 in this process. These numbers are known as sad numbers or unhappy numbers.

Example
32 is a happy number:

\[\begin{align} 3^2+2^2 &= 13\\1^2+3^2 &= 10\\1^2+0^2 &= 1\end{align}\]

List to 250
1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100, 103, 109, 129, 130, 133, 139, 167, 176, 188, 190, 192, 193, 203, 208, 219, 226, 230, 236, 239

Mathematical properties
A happy number will always end up with 1, or it will end up in this cycle:

20, 4, 16, 37, 58, 89, 145, 42.

Variants of this exist, using cubing instead of squaring, and taking the digits to the fourth power.

All powers of 10 are happy numbers for all variants (except taking \(n^0\) in base 10), and numbers of the form \(10^n+3\) and \(10^n+9\) for n more than 0 are happy numbers.