Posts

Showing posts with the label programming problem

Happy Numbers

Happy Numbers Problem Problem: We'll say that for a positive whole number n, the squareSum of n is the sum of the squares of the digits of n. So if n is 1406, then squareSum(n) is 1^(2) + 4^(2) + 0^(2) + 6^(2) = 1 + 16 + 0 + 36 = 53. We further say that the k^(th)-squareSum of n is squareSum(squareSum(...(squareSum(n)))), where squareSum is composed k-many times. For example, the 3rdsquareSum of 1406 is squareSum(squareSum(squareSum(1406))) = squareSum(squareSum(53)) (as we know from above) = squareSum(5^(2) + 3^(2)) = squareSum(25 + 9) = squareSum(34) = 3^(2) + 4^(2) = 9 + 16 = 25. Definition: A number n is happy if for some positive integer m, the m^(th)-squareSum of n is equal to 1. Problem: Find the first N happy numbers for any given positive integer N. Aspects that made this problem interesting: Let the squareSum be the sum of the squares of a numbers digits. Then squareSum(number1) = squareSum(number2) if number1 is a permutation of the digits of numb