Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. /*
  2. Happy numbers
  3.  
  4. Given a number n. Find all of the happy numbers from 1 to n
  5.  
  6. Given any number, take the sum of the squares of all digits of that number
  7. Continue until either the sum equals 1, or the sum equals a number that has been seen previously (loop)
  8.  
  9. Is 13 happy?
  10. 1^2 + 3^2 = 1 + 9 = 10
  11. 1^2 + 0^2 = 1
  12. ->Happy
  13.  
  14. Is 11 happy?
  15. 1^2 + 1^2 = 1 + 1 = 2
  16. 2^2 = 4
  17. 4^2 = 16
  18. 1^2 + 6^2 = 1 + 36 = 37
  19. 3^2 + 7^2 = 9 + 49 = 58
  20. 5^2 + 8^2 = 25 + 64 = 89
  21. 8^2 + 9^2 = 64 + 81 = 145
  22. 1^2 + 4^2 + 5^2 = 1 + 16 + 25 = 42
  23. 4^2 + 2^2 = 16 + 4 = 20
  24. 2^2 + 0^2 = 4
  25. ->Unhappy
  26. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement