source/euler30.rb
def digit_powers(power)
  sums = []
  # First I was wrong because I assumed they all had to be five digits; then I
  # was wrong becaus the assumption is that 1 doesn't count, maybe because
  # valid sums are two digits.
  (10...10**7).each do |candidate|
    digits = candidate.to_s.split("").map(&:to_i)
    sum = digits.map {|digit| digit**power}.inject(:+)
    sums << candidate if candidate == sum
  end
  sums
end
# Find the sum of all the numbers that can be written as the sum of fifth 
# powers of their digits.
Find the sum of all the numbers that can be written as the sum of fifth
powers of their digits.
Find the sum of all the numbers that can be written as the sum of fifth powers of their digits .
def digit_powers(power)
  sums = []
  (10...10**7).each do |candidate|
    digits = candidate.to_s.split("").map(&:to_i)
    sum = digits.map {|digit| digit**power}.inject(:+)
    sums << candidate if candidate == sum
  end
  sums
end
def digit_powers ( power ) sums = [ ] ( 10 ... 10 ** 7 ) . each do | candidate | digits = candidate . to_s . split ( "" ) . map ( & :to_i ) sum = digits . map { | digit | digit ** power } . inject ( :+ ) sums << candidate if candidate == sum end sums end
Find the sum of all the numbers that can be written as the sum of fifth
powers of their digits.
Find the sum of all the numbers that can be written as the sum of fifth powers of their digits .
# First I was wrong because I assumed they all had to be five digits; then I # was wrong becaus the assumption is that 1 doesn't count, maybe because # valid sums are two digits.
power