RosettaCodeData/Task/Own-digits-power-sum/Ruby/own-digits-power-sum.rb
2023-07-01 13:44:08 -04:00

13 lines
315 B
Ruby

DIGITS = (0..9).to_a
range = (3..18)
res = range.map do |s|
powers = {}
DIGITS.each{|n| powers[n] = n**s}
DIGITS.repeated_combination(s).filter_map do |combi|
sum = powers.values_at(*combi).sum
sum if sum.digits.sort == combi.sort
end.sort
end
puts "Own digits power sums for N = #{range}:", res