diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-12-05 22:00:18 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-12-05 22:00:18 +0100 |
commit | b36e0aeb8eea55d8378da4577225f27a8ca47403 (patch) | |
tree | df5b089e7d5a2d99a1dfd74e27c09f47bfab8347 | |
parent | ce3c1cc4b9c0494362a15c4ddcf6f42a8a7edd28 (diff) |
day 4 part 2
-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()))}") |