summaryrefslogtreecommitdiff
path: root/04
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-12-05 22:00:18 +0100
committerlonkaars <loek@pipeframe.xyz>2023-12-05 22:00:18 +0100
commitb36e0aeb8eea55d8378da4577225f27a8ca47403 (patch)
treedf5b089e7d5a2d99a1dfd74e27c09f47bfab8347 /04
parentce3c1cc4b9c0494362a15c4ddcf6f42a8a7edd28 (diff)
day 4 part 2
Diffstat (limited to '04')
-rwxr-xr-x04/main.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/04/main.py b/04/main.py
index 1c42aa4..dfe63d9 100755
--- a/04/main.py
+++ b/04/main.py
@@ -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()))}")