From ce3c1cc4b9c0494362a15c4ddcf6f42a8a7edd28 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Mon, 4 Dec 2023 19:02:03 +0100 Subject: day 4 part 1 --- 04/main.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 04/main.py diff --git a/04/main.py b/04/main.py new file mode 100755 index 0000000..1c42aa4 --- /dev/null +++ b/04/main.py @@ -0,0 +1,25 @@ +#!/bin/python3 +import sys +import re + +sum = 0 +for line in sys.stdin: + line = line.strip() + card_id, sets = line.split(":") + card_id = int(re.sub("[^0-9]", "", card_id)) + + winning_set, holding_set = sets.split("|") + + winning_numbers = set(winning_set.split()) + holding_numbers = set(holding_set.split()) + + points = 0 + for num in holding_numbers: + if num in winning_numbers: + points += 1 + + if points > 0: + sum += 2 ** (points - 1) + +print(f">> {sum}") + -- cgit v1.2.3