euler/ruby/euler030.rb

13 lines
295 B
Ruby
Raw Normal View History

2014-04-25 23:59:14 +00:00
def sum_of_fifth_powers(num)
list_of_digits = num.to_s.split("").map(&:to_i)
list_of_digits.map { |digit| digit**5 }.inject(:+)
end
equivalent_sums = []
(10..1000000).each do |num|
sum = sum_of_fifth_powers(num)
equivalent_sums << num if sum == num
end
puts equivalent_sums.inject(:+)