2023-12-01 10:23:08 -05:00
|
|
|
#!/usr/bin/env python3
|
2023-12-01 09:29:09 -05:00
|
|
|
import sys
|
2023-12-04 13:05:07 -05:00
|
|
|
from dataclasses import dataclass
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class Row:
|
|
|
|
cards: int
|
|
|
|
matches: int
|
2023-12-01 12:01:22 -05:00
|
|
|
|
2023-12-01 09:29:09 -05:00
|
|
|
sum = 0
|
2023-12-04 13:05:07 -05:00
|
|
|
rows = []
|
2023-12-01 09:29:09 -05:00
|
|
|
for line in sys.stdin:
|
2023-12-04 13:04:44 -05:00
|
|
|
_, nums = line.split(":")
|
|
|
|
winning, mine = nums.split("|")
|
2023-12-01 12:01:22 -05:00
|
|
|
|
2023-12-04 13:04:44 -05:00
|
|
|
winning = set(winning.split())
|
|
|
|
mine = set(mine.split())
|
2023-12-01 12:01:22 -05:00
|
|
|
|
2023-12-04 13:04:44 -05:00
|
|
|
both = winning.intersection(mine)
|
2023-12-04 13:05:07 -05:00
|
|
|
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)
|
2023-12-01 09:29:09 -05:00
|
|
|
|
|
|
|
print(sum)
|