diff options
Diffstat (limited to '04')
-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}") + |