-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
35 lines (29 loc) · 824 Bytes
/
script.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
from GhostyUtils import aoc
if __name__ == '__main__':
inputs = aoc.read_lines()
num_cards = len(inputs)
total = 0
copies = {n+1: 1 for n in range(num_cards)}
for num, card in enumerate(inputs):
win, have = card.split(' | ')
win = win.split(': ')[1].split()
have = have.split()
# p1
score = 0
for h in have:
if h in win:
if score == 0:
score = 1
else:
score *= 2
total += score
# p2
matches = 0
for h in have:
if h in win:
matches += 1
for i in range(1, matches+1):
if num+1+i in copies:
copies[num+1+i] += copies[num+1]
print(total)
print(sum(copies.values()))