-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathday_07.py
43 lines (29 loc) · 864 Bytes
/
day_07.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
def part_01():
with open('input_07.txt') as d:
lines = list(map(int, d.read().strip().split(',')))
fuels = []
for i in range(min(lines), max(lines)):
crab = []
for l in lines:
crab.append(abs(l - i))
fuels.append(sum(crab))
return min(fuels)
# This is hella slow, but the best I could figure out while unpacking
# in a new house and looking after a baby
def part_02():
with open('input_07.txt') as d:
lines = list(map(int, d.read().strip().split(',')))
least_fuel = 0
for i in range(min(lines), max(lines)):
crab = []
for l in lines:
crab_fuel = []
for j in range(0, abs(l - i + 1)):
crab_fuel.append(j + 1)
crab.append(sum(crab_fuel))
fuel = sum(crab)
if fuel < least_fuel or least_fuel == 0:
least_fuel = fuel
return least_fuel
print('Part 1:', part_01())
print('Part 2:', part_02())