Happy Numbers
Given an integer n, we apply this transformation until it becomes a 1: take each of the digits in n, square it, and then take their sum.
Return whether n will end up in 1 after the transformations.
https://binarysearch.com/problems/Happy-Numbers
Examples
Example 1
Input
- n = 
7 
Output
- answer = 
True 
Explanation
This is a happy number since we get this sequence [49, 97, 130, 10, 1]
7 ** 2 = 494 ** 2 + 9 ** 2 = 979 ** 2 + 7 ** 2 = 1301 ** 2 + 3 ** 2 + 0 ** 2 = 101 ** 2 + 0 ** 2 = 1
Example 2
Input
- n = 
11 
Output
- answer = 
False 
Explanation
This is not a happy number since it ends up in a cycle: [2, 4, 16, 37, 58, 89, 145, 42, 20, 4]
2 ** 2 = 44 ** 2 = 161 ** 2 + 6 ** 2 = 373 ** 2 + 7 ** 2 = 585 ** 2 + 8 ** 2 = 898 ** 2 + 9 ** 2 = 1451 ** 2 + 4 ** 2 + 5 ** 2 = 424 ** 2 + 2 ** 2 = 202 ** 2 + 0 ** 2 = 4
      
      
Leave a comment