diff options
Diffstat (limited to '04')
-rwxr-xr-x | 04/main.py | 21 |
1 files changed, 11 insertions, 10 deletions
@@ -2,24 +2,25 @@ import sys import re -sum = 0 +card_count_map = {} for line in sys.stdin: line = line.strip() card_id, sets = line.split(":") card_id = int(re.sub("[^0-9]", "", card_id)) + card_count_map[card_id] = card_count_map.get(card_id, 1) - winning_set, holding_set = sets.split("|") + winning_numbers, holding_numbers = [set(x.split()) for x in sets.split("|")] - winning_numbers = set(winning_set.split()) - holding_numbers = set(holding_set.split()) - - points = 0 + matches = 0 for num in holding_numbers: if num in winning_numbers: - points += 1 + matches += 1 - if points > 0: - sum += 2 ** (points - 1) + print(f"card {card_id} has {matches} matches") + for x in range(matches): + index = card_id + x + 1 + card_count_map[index] = card_count_map.get(index, 1) + card_count_map[card_id] + print(f"card_count_map[{index}] = {card_count_map[index]}") -print(f">> {sum}") +print(f">> {sum(list(card_count_map.values()))}") |