From bb31161c80ed2d02e450e98ea94e1e277ea689d5 Mon Sep 17 00:00:00 2001 From: Isaac Shoebottom Date: Tue, 3 Dec 2024 14:56:29 -0400 Subject: [PATCH] No need for defs --- 2024/03/solution.py | 48 +++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/2024/03/solution.py b/2024/03/solution.py index 49d47b8..a5a11a9 100644 --- a/2024/03/solution.py +++ b/2024/03/solution.py @@ -3,30 +3,26 @@ import re data = get_data(day=3, year=2024) -def part_one(): - matches = re.findall(r"mul\((\d+),(\d+)\)", data, re.MULTILINE) - total = 0 - for match in matches: - total += int(match[0]) * int(match[1]) - print(total) +# Part one +matches = re.findall(r"mul\((\d+),(\d+)\)", data, re.MULTILINE) +total = 0 +for match in matches: + total += int(match[0]) * int(match[1]) +print(total) -def part_two(): - matches = re.finditer(r"mul\((\d+),(\d+)\)", data, re.MULTILINE) - total = 0 - for match in matches: - start = match.start() - do_match = data.rfind("do()", 0, start) - dont_match = data.rfind("don't()", 0, start) - - if do_match == dont_match == -1: # Neither - total += int(match.group(1)) * int(match.group(2)) - continue - if do_match > dont_match: # Do - total += int(match.group(1)) * int(match.group(2)) - continue - else: # Don't - continue - print(total) - -part_one() -part_two() \ No newline at end of file +# Part two +matches = re.finditer(r"mul\((\d+),(\d+)\)", data, re.MULTILINE) +total = 0 +for match in matches: + start = match.start() + do_match = data.rfind("do()", 0, start) + dont_match = data.rfind("don't()", 0, start) + if do_match == dont_match == -1: # Neither + total += int(match.group(1)) * int(match.group(2)) + continue + if do_match > dont_match: # Do + total += int(match.group(1)) * int(match.group(2)) + continue + else: # Don't + continue +print(total) \ No newline at end of file