blob: 6f70fe7fad2c2e20bacdb566b85fdfad537e5f73 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
#!/usr/bin/env ruby
def fuel_required(mass)
fuel_queue = [mass]
loop do
new_fuel = (fuel_queue.last / 3) - 2
return (fuel_queue.sum - mass) if new_fuel <= 0
fuel_queue << new_fuel
end
end
input = $stdin.readlines.map(&:strip).map(&:to_i)
puts input.map{ |x| fuel_required(x) }.sum
|