From 8e313e2614c7a0fe5af924febdbacc650e33835e Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Sat, 15 Jun 2024 22:20:32 -0600 Subject: intial --- 4_2023.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 4_2023.py (limited to '4_2023.py') 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())) -- cgit v1.2.3