aoc2023/solve.py

31 lines
566 B
Python
Executable file

#!/usr/bin/env python3
import sys
from dataclasses import dataclass
@dataclass
class Row:
cards: int
matches: int
sum = 0
rows = []
for line in sys.stdin:
_, nums = line.split(":")
winning, mine = nums.split("|")
winning = set(winning.split())
mine = set(mine.split())
both = winning.intersection(mine)
rows.append(Row(matches=len(both), cards=1))
for i in range(len(rows)):
m = rows[i]
for j in range(m.matches):
rows[i + 1 + j].cards += m.cards
for row in rows:
sum += row.cards
print(row)
print(sum)