02
This commit is contained in:
25
03/03-01.py
Normal file
25
03/03-01.py
Normal 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}')
|
||||
Reference in New Issue
Block a user