-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday_8.py
More file actions
29 lines (23 loc) · 678 Bytes
/
day_8.py
File metadata and controls
29 lines (23 loc) · 678 Bytes
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
with open('files/day_8_input.txt') as f:
data = [int(x) for x in f.read().split()]
def parse(data):
children, metas = data[:2]
data = data[2:]
scores = []
totals = 0
for i in range(children):
total, score, data = parse(data)
totals += total
scores.append(score)
totals += sum(data[:metas])
if children == 0:
return (totals, sum(data[:metas]), data[metas:])
else:
return (
totals,
sum(scores[k - 1] for k in data[:metas] if k > 0 and k <= len(scores)),
data[metas:]
)
total, value, remaining = parse(data)
print('part 1:', total)
print('part 2:', value)