A happy number is defined by the following process. Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process un
As long as the current number has more than 3 digits, it's value decreases in the next iteration. When the number has 3 digits, the maximum value it can take in the next iteration is 3*81 <= 250. So use an array of size 250 and record all the numbers in the sequence that are less than 250. You can then easily detect if you have a duplicate.