diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-12-04 19:02:03 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-12-04 19:02:03 +0100 |
commit | ce3c1cc4b9c0494362a15c4ddcf6f42a8a7edd28 (patch) | |
tree | c98f4dc6f3092e00f200123d2231f05fbcfea034 | |
parent | e275c8c30af198c17a84d0ac288154df51282b77 (diff) |
day 4 part 1
-rwxr-xr-x | 04/main.py | 25 |
1 files changed, 25 insertions, 0 deletions
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}") + |