No need for defs

This commit is contained in:
Isaac Shoebottom 2024-12-03 14:56:29 -04:00
parent cb4f3d26d0
commit bb31161c80

View File

@ -3,30 +3,26 @@ import re
data = get_data(day=3, year=2024) data = get_data(day=3, year=2024)
def part_one(): # Part one
matches = re.findall(r"mul\((\d+),(\d+)\)", data, re.MULTILINE) matches = re.findall(r"mul\((\d+),(\d+)\)", data, re.MULTILINE)
total = 0 total = 0
for match in matches: for match in matches:
total += int(match[0]) * int(match[1]) total += int(match[0]) * int(match[1])
print(total) print(total)
def part_two(): # Part two
matches = re.finditer(r"mul\((\d+),(\d+)\)", data, re.MULTILINE) matches = re.finditer(r"mul\((\d+),(\d+)\)", data, re.MULTILINE)
total = 0 total = 0
for match in matches: for match in matches:
start = match.start() start = match.start()
do_match = data.rfind("do()", 0, start) do_match = data.rfind("do()", 0, start)
dont_match = data.rfind("don't()", 0, start) dont_match = data.rfind("don't()", 0, start)
if do_match == dont_match == -1: # Neither
if do_match == dont_match == -1: # Neither total += int(match.group(1)) * int(match.group(2))
total += int(match.group(1)) * int(match.group(2)) continue
continue if do_match > dont_match: # Do
if do_match > dont_match: # Do total += int(match.group(1)) * int(match.group(2))
total += int(match.group(1)) * int(match.group(2)) continue
continue else: # Don't
else: # Don't continue
continue print(total)
print(total)
part_one()
part_two()