2024(3): solve 1

Co-Authored-By: Marit Nuijten <marit.nuijten@gmail.com>
This commit is contained in:
2024-12-18 19:36:19 +01:00
parent 1789a98c8a
commit b98a82e42b

17
2024/3/1.py Normal file
View File

@ -0,0 +1,17 @@
import re
regex = r"mul\((\d{1,3}),(\d{1,3})\)"
c = re.compile(regex)
def process_line(line):
return sum([int(x)*int(y) for x, y in c.findall(line)])
#test = "xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))"
result = 0
with open("input", "r") as fp:
while (line := fp.readline()):
result += process_line(line)
print(f"The sum of all multiplications equals {result}.")