-
Notifications
You must be signed in to change notification settings - Fork 0
/
day1.py
49 lines (33 loc) · 1.12 KB
/
day1.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
# vi: set shiftwidth=4 tabstop=4 expandtab:
import datetime
def get_modules_from_file(file_path="day1_input.txt"):
with open(file_path) as f:
return [int(l.strip()) for l in f]
def get_fuel_requirement(weight):
return (weight // 3) - 2
def get_fuel_requirement2(weight):
ret = 0
while True:
weight = (weight // 3) - 2
if weight <= 0:
break
ret += weight
return ret
def get_full_fuel_requirement(modules):
return sum(get_fuel_requirement(m) for m in modules)
def get_full_fuel_requirement2(modules):
return sum(get_fuel_requirement2(m) for m in modules)
def run_tests():
modules = [12, 14, 1969, 100756]
assert get_full_fuel_requirement(modules) == 2 + 2 + 654 + 33583
assert get_full_fuel_requirement2(modules) == 2 + 2 + 966 + 50346
def get_solutions():
modules = get_modules_from_file()
print(get_full_fuel_requirement(modules))
print(get_full_fuel_requirement2(modules))
if __name__ == "__main__":
begin = datetime.datetime.now()
run_tests()
get_solutions()
end = datetime.datetime.now()
print(end - begin)