n and keep applying one step: replace the number with the sum of the squares of its digits. For example, 23 becomes 2² + 3² = 13.
Sooner or later the sequence either reaches 1 (and stays there) or falls into a loop that never contains 1.
Return True if starting from n you eventually reach 1, and False otherwise.n=7 → True
7 → 49 → 16 + 81 = 97 → 81 + 49 = 130 → 1 + 9 + 0 = 10 → 1. We reach one.
n=4 → False
4 → 16 → 37 → 58 → 89 → 145 → 42 → 20 → 4: the sequence is back at 4 and will keep cycling without ever hitting 1.
n=1 → True
n ≤ 2³¹ − 1n=7
True
Run checks the first 3 tests in your browser. Submit checks all 56 tests on the server, hidden ones included.