Unhappy Number

Unhappy Number

The process is to take a positive integer and replace the number with the sum of the squares of the digits. Repeat the process until it either ends in 1 ( happy number) or the number repeats in a cycle. If the cycle repeats, the number is known as an unhappy number. Here’s an example using the number 5:

52 = 25

25 = 22 + 52 = 4 + 25 = 29

29 = 22 + 92 = 4 + 81 = 85

85 = 82 + 52 = 64 + 25 = 89

89 = 82 + 92 = 64 + 81 = 145

145 = 12 + 42 + 52 = 1 + 16 + 25 = 42

42 = 42 + 22 = 16 + 4 = 20

20 = 22 + 02 = 4

4 = 42 = 16

16 = 12 + 62 = 1 + 36 = 37

37 = 32 + 72 = 9 + 49 = 58

58 = 52 + 82 = 25 + 64 = 89 = UNHAPPY :(