My attempt to solve Project Euler no. 30 in Ruby
a = 1..9999
def ret_sum_of_power(number)
  numbers_array = number.to_a
  my_total = 0
  numbers_array.each do |my_num|
    my_total = my_total + my_num ** 4
  end
  return my_total
end
a.each do |my_a|
  if ret_sum_of_power(my_a) == my_a
    puts my_a
  end
end
No comments:
Post a Comment