In [9]:
def sum_digit(number)
  number.to_s.split("").map{|n|n.to_i}.inject(:+)
end

In [10]:
max = 0

(1..99).each do |x|
  (1..99).each do |y|
    temp = sum_digit(x**y)
    max = temp if temp > max
  end
end

max


Out[10]:
972

In [ ]: