Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 17th, 2012  |  syntax: None  |  size: 0.78 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Write a program that tells whether a given integer is happy. A happy number is found using the following process: Take the sum of the squares of its digits, and continue iterating this process until it yields 1, or produces an infinite loop.
  2. ( Hint: http://mathworld.wolfram.com/HappyNumber.html, http://oeis.org/A039943 )
  3.  
  4. For example the number 7:
  5. 7^2 = 49
  6. 4^2 + 9^2 = 97
  7. 9^2 + 7^2 = 130
  8. 1^2 + 3^2 + 0^2 = 10
  9. 1^2 + 0^2 = 1
  10.  
  11. If a number is not happy than it is obviously unhappy.
  12. Now that you have this program, what is the largest happy number you can find?
  13. What is the happiest number between 1 and 1,000,000.
  14. Defined the happiest number as the smallest number that finds the most other happy numbers with it, i.e. 7 found four other numbers (49, 97, 130, and 10) making it a rank 4 in happiness.