Skip to content

Instantly share code, notes, and snippets.

@timrandg
Created January 25, 2012 07:13
Show Gist options
  • Select an option

  • Save timrandg/1675177 to your computer and use it in GitHub Desktop.

Select an option

Save timrandg/1675177 to your computer and use it in GitHub Desktop.
#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