Day 4 completed

+ refactored day 1 to 3 with black -l 119
This commit is contained in:
2023-12-04 07:44:36 +01:00
parent 97021a58b2
commit 142696bf6e
7 changed files with 103 additions and 29 deletions

27
day4/part1.py Executable file
View File

@@ -0,0 +1,27 @@
#!/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)