No need for defs
This commit is contained in:
parent
cb4f3d26d0
commit
bb31161c80
@ -3,21 +3,20 @@ 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:
|
||||
# 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)
|
||||
print(total)
|
||||
|
||||
def part_two():
|
||||
matches = re.finditer(r"mul\((\d+),(\d+)\)", data, re.MULTILINE)
|
||||
total = 0
|
||||
for match in matches:
|
||||
# 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
|
||||
@ -26,7 +25,4 @@ def part_two():
|
||||
continue
|
||||
else: # Don't
|
||||
continue
|
||||
print(total)
|
||||
|
||||
part_one()
|
||||
part_two()
|
||||
print(total)
|
Loading…
x
Reference in New Issue
Block a user