25 lines
608 B
Python
25 lines
608 B
Python
#!/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}') |