2023/day4/part1.py
Fedaya 142696bf6e Day 4 completed
+ refactored day 1 to 3 with black -l 119
2023-12-04 07:44:36 +01:00

28 lines
980 B
Python
Executable File

#!/usr/bin/env python3.11
import re
input_file = "input.txt"
sum = 0
with open(input_file) as input:
while line := input.readline():
if match := re.match("Card +(\d+): (.*) \| (.*)", line):
winning_numbers = list(map(int, re.split(" +", match.group(2).lstrip(" "))))
numbers = map(int, re.split(" +", match.group(3).lstrip(" ")))
# print(match.group(1), winning_numbers, numbers)
points = 0
# print(winning_numbers, end="; ")
for number in numbers:
# print(number, end=",")
if number in winning_numbers:
# print("is winning", end="; ")
if points == 0:
points = 1
else:
points *= 2
else:
# print("is not winning", end="; ")
pass
# print("\n", points)
sum += points
print(sum)