A googol (10[sup]100[/sup]) is a massive number: one followed by one-hundred zeros; 100[sup]100[/sup] 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, a[sup]b[/sup], where a, b < 100, what is the maximum digital sum?
max = 0
(1..100).each do |a|
(1..100).each do |b|
w = (a ** b).to_s.split('').map {|x| x.to_i}.inject {|sum,n| sum + n}
max = w if w > max
end
end
p max