Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Happy numbers
- Given a number n. Find all of the happy numbers from 1 to n
- Given any number, take the sum of the squares of all digits of that number
- Continue until either the sum equals 1, or the sum equals a number that has been seen previously (loop)
- Is 13 happy?
- 1^2 + 3^2 = 1 + 9 = 10
- 1^2 + 0^2 = 1
- ->Happy
- Is 11 happy?
- 1^2 + 1^2 = 1 + 1 = 2
- 2^2 = 4
- 4^2 = 16
- 1^2 + 6^2 = 1 + 36 = 37
- 3^2 + 7^2 = 9 + 49 = 58
- 5^2 + 8^2 = 25 + 64 = 89
- 8^2 + 9^2 = 64 + 81 = 145
- 1^2 + 4^2 + 5^2 = 1 + 16 + 25 = 42
- 4^2 + 2^2 = 16 + 4 = 20
- 2^2 + 0^2 = 4
- ->Unhappy
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement