A happy number is defined as:

A number which, when replaced by the sum of the digits squared and repeated infinitely, will equal in a series of ‘1’

The operation to detect a happy number is:

- Split the individual digits of a number (eg. 523 becomes 5,2 and 3)
- Square each of these number (25,4 and 9)
- Add these squares together (25+4+9=38)
- Is your new number equal to 1? If so you have a happy number else return to step 1 with your newly calculated number

If your number produces an infinitely recurring loop of numbers that do not result in 1 then your number is not a happy number and therefore unhappy.

List of happy numbers below 1000

**Examples**

293

4+81+9=94

81+16=97

81+49=130

1+9=10

1

293 Is a happy number

And an example of an unhappy number:

294

4+81+16=101

1+1=2

4=4

16=16

1+36=37

9+49=58

25+64=89

64+81=145

1+16+25=42

16+4=20

4=4

…..

294 is not a happy number

In the second example we see that 294 is not a happy number because it produces a recurring loop: 4,16,37,58,89,145,42,20. This is the standard unhappy loop, once you have any of these numbers your number must be unhappy as this will cause an infinite loop.