This commit is contained in:
2024-12-03 09:13:31 +01:00
parent ae0b3d9871
commit e3da406cb3
5 changed files with 65 additions and 0 deletions

25
03/03-01.py Normal file
View File

@@ -0,0 +1,25 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
def mul(m:str) -> int:
pattern = r"(\d+),(\d+)"
match = re.search(pattern, m)
return int(match.group(1)) * int(match.group(2))
def parse_mul(l:str) -> int:
result = 0
pattern = r'mul\(\d+,\d+\)'
matches = re.findall(pattern, l)
print(matches)
for match in matches:
result += mul(match)
return result
if __name__ == "__main__":
solution = 0
input_file = open("input.txt", "r")
for line in input_file:
solution += parse_mul(line)
input_file.close()
print(f'Solution:{solution}')