summaryrefslogtreecommitdiff
path: root/4_2023.py
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2024-06-15 22:20:32 -0600
committerJack Sangdahl <[email protected]>2024-06-15 22:20:32 -0600
commit8e313e2614c7a0fe5af924febdbacc650e33835e (patch)
tree63426b6942ceebe17708140c972a7d7451bd2f74 /4_2023.py
downloadaoc-8e313e2614c7a0fe5af924febdbacc650e33835e.tar.gz
aoc-8e313e2614c7a0fe5af924febdbacc650e33835e.zip
intial
Diffstat (limited to '4_2023.py')
-rw-r--r--4_2023.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/4_2023.py b/4_2023.py
new file mode 100644
index 0000000..f634cbc
--- /dev/null
+++ b/4_2023.py
@@ -0,0 +1,21 @@
+import sys
+import re
+from collections import defaultdict
+
+D = open(sys.argv[1]).read().strip()
+lines = D.split("\n")
+p1 = 0
+N = defaultdict(int)
+for i, line in enumerate(lines):
+ N[i] += 1
+ first, rest = line.split("|")
+ id_, card = first.split(":")
+ card_nums = [int(x) for x in card.split()]
+ rest_nums = [int(x) for x in rest.split()]
+ val = len(set(card_nums) & set(rest_nums))
+ if val > 0:
+ p1 += 2 ** (val - 1)
+ for j in range(val):
+ N[i + j + 1] += N[i]
+print(p1)
+print(sum(N.values()))