You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.1 KiB
Python
56 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Part1"""
|
|
|
|
import sys
|
|
from collections import defaultdict
|
|
|
|
RESULT = 0
|
|
|
|
CARD_NUMS = []
|
|
CARD_WORTHS = {}
|
|
CARDS_COUNTS = defaultdict(int)
|
|
|
|
for line in sys.stdin.readlines():
|
|
line = line.strip()
|
|
card_no, numbers = line.split(": ")
|
|
|
|
card_no = card_no.split()[1]
|
|
card_no = int(card_no)
|
|
CARD_NUMS.append(card_no)
|
|
print("processing", card_no)
|
|
|
|
CARDS_COUNTS[card_no] += 1
|
|
|
|
numbers_win, numbers_have = numbers.split(" | ")
|
|
numbers_win = set(numbers_win.split())
|
|
numbers_have = set(numbers_have.split())
|
|
|
|
matches = numbers_win & numbers_have
|
|
num_matches = len(matches)
|
|
|
|
for num in range(card_no + 1, card_no + num_matches + 1):
|
|
print("add num", num)
|
|
CARDS_COUNTS[num] += CARDS_COUNTS[card_no]
|
|
|
|
worth = 2 ** (num_matches - 1)
|
|
worth = int(worth)
|
|
|
|
CARD_WORTHS[card_no] = worth
|
|
|
|
print()
|
|
print(CARD_NUMS)
|
|
print(CARDS_COUNTS)
|
|
print(CARD_WORTHS)
|
|
|
|
print()
|
|
RESULT = 0
|
|
for card_no in CARD_NUMS:
|
|
count = CARDS_COUNTS[card_no]
|
|
worth = CARD_WORTHS[card_no]
|
|
|
|
print(f"{card_no}: {count:3} x {worth:3} pts")
|
|
RESULT += count
|
|
|
|
print()
|
|
print(RESULT)
|