Make space for two-digit days
This commit is contained in:
parent
0967b498c7
commit
07eb60e5e1
29 changed files with 0 additions and 1584 deletions
|
|
@ -1,24 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
def fuel_needed(mass)
|
||||
[(mass / 3).truncate - 2, 0].max
|
||||
end
|
||||
|
||||
def total_fuel(mass)
|
||||
fuel = 0
|
||||
current = mass
|
||||
while current.positive?
|
||||
current = fuel_needed(current)
|
||||
fuel += current
|
||||
end
|
||||
fuel
|
||||
end
|
||||
|
||||
fuel = 0
|
||||
File.open(File.join(__dir__, 'input')) do |file|
|
||||
file.readlines.each do |line|
|
||||
mass = line.to_i
|
||||
fuel += total_fuel(mass)
|
||||
end
|
||||
end
|
||||
puts fuel
|
||||
Loading…
Reference in a new issue