Created
January 25, 2012 07:13
-
-
Save timrandg/1675177 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #project_euler problem_56 | |
| #A googol (10**100) is a massive number: one followed by one-hundred zeros; 100**100 is almost unimaginably large: one followed by two-hundred zeros. Despite their size, the sum of the digits in each number is only 1. | |
| #Considering natural numbers of the form, ab, where a, b 100, what is the maximum digital sum? | |
| sum_of_digits =->(a,b){ (a**b).to_s.split('').collect(&:to_i).inject(&:+) } | |
| max_of =->(y, z){ y > z ? y : z} | |
| for a in (1..99) | |
| for b in (1..99) | |
| @max = max_of.(sum_of_digits.(a,b), @max ||= 0) | |
| end | |
| end | |
| p @max |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment