28 lines
980 B
Python
Executable File
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)
|