-
Notifications
You must be signed in to change notification settings - Fork 0
/
day01.py
executable file
·51 lines (32 loc) · 856 Bytes
/
day01.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
import aoc
def fuel_required_per_mass(mass):
return mass // 3 - 2
def fuel_required(mass):
total_fuel = 0
while True:
fuel = fuel_required_per_mass(mass)
if fuel > 0:
total_fuel += fuel
mass = fuel
else:
break
return total_fuel
def part1(input_list):
"""
Calculate fuel mass for ship.
"""
total_fuel_required = 0
for mass in input_list:
total_fuel_required += fuel_required_per_mass(int(mass))
return total_fuel_required
def part2(input_list):
"""
Calculate fuel mass for ship and added fuel.
"""
total_fuel_required = 0
for mass in input_list:
total_fuel_required += fuel_required(int(mass))
return total_fuel_required
if __name__ == "__main__":
aoc.main(part1, part2)