From c9141da37ae1911cc9caad5bb15b885aedcce6d3 Mon Sep 17 00:00:00 2001 From: Heiko Ludwig Date: Tue, 3 Dec 2024 20:38:58 +0100 Subject: [PATCH] compile regex pattern only once --- day_03/program.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/day_03/program.py b/day_03/program.py index e990273..bd5f517 100755 --- a/day_03/program.py +++ b/day_03/program.py @@ -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