summaryrefslogtreecommitdiff
path: root/4_2023.py
blob: f634cbca4857705be408f309c925f5f0d69b2003 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import sys
import re
from collections import defaultdict

D = open(sys.argv[1]).read().strip()
lines = D.split("\n")
p1 = 0
N = defaultdict(int)
for i, line in enumerate(lines):
    N[i] += 1
    first, rest = line.split("|")
    id_, card = first.split(":")
    card_nums = [int(x) for x in card.split()]
    rest_nums = [int(x) for x in rest.split()]
    val = len(set(card_nums) & set(rest_nums))
    if val > 0:
        p1 += 2 ** (val - 1)
    for j in range(val):
        N[i + j + 1] += N[i]
print(p1)
print(sum(N.values()))