Replace n with the sum of the squares of its digits, and repeat. If you reach 1 the number is happy; if you instead loop forever in a cycle that never contains 1, it is not. Return True for a happy number.
For example 19 is happy: 1² + 9² = 82, 8² + 2² = 68, 6² + 8² = 100, 1² + 0² + 0² = 1.
Example 1
Input:
happy_number(19)
Output:
True
19 -> 82 -> 68 -> 100 -> 1.
Example 2
Input:
happy_number(2)
Output:
False
2 falls into a cycle that never reaches 1.
1 <= n <= 2**31 - 1No results yet
Run your code to check it against the examples, or submit to run every test.