You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
advent-of-code/2019/ruby/day_01.rb

16 lines
263 B

# puts ARGF.read.lines.map(&:to_i).map {|mass|
# (mass / 3.0).floor - 2
# }.sum
fuel = ->(mass) {
total = 0
loop do
mass = (mass / 3.0).floor - 2
break if mass <= 0
total += mass
end
total
}
puts ARGF.read.lines.map(&:to_i).map(&fuel).sum