Day 4 completed
+ refactored day 1 to 3 with black -l 119
This commit is contained in:
27
day4/part1.py
Executable file
27
day4/part1.py
Executable 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)
|
||||
Reference in New Issue
Block a user