compile regex pattern only once

This commit is contained in:
Heiko Ludwig 2024-12-03 20:38:58 +01:00
parent 7c669afb2c
commit c9141da37a

View file

@ -12,8 +12,9 @@ def get_lines(filename: str) -> list:
def part1_get_result_sum(lines: list) -> int:
result_sum = 0
pattern = re.compile(r"mul\((\d+),(\d+)\)")
for line in lines:
matches = re.findall(r"mul\((\d+),(\d+)\)", line)
matches = re.findall(pattern, line)
for match in matches:
result_sum += int(match[0]) * int(match[1])
return result_sum