Compare commits

..

2 Commits

Author SHA1 Message Date
e97762a3f7 Add one liner 2024-12-03 15:01:48 -04:00
fa259faa2b Remove unneeded continue logic 2024-12-03 14:58:13 -04:00

View File

@@ -10,6 +10,9 @@ for match in matches:
total += int(match[0]) * int(match[1])
print(total)
# One-liner
# print(sum(int(x) * int(y) for x, y in re.findall(r"mul\((\d+),(\d+)\)", data, re.MULTILINE)))
# Part two
matches = re.finditer(r"mul\((\d+),(\d+)\)", data, re.MULTILINE)
total = 0
@@ -19,10 +22,6 @@ for match in matches:
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
elif do_match > dont_match: # Do
total += int(match.group(1)) * int(match.group(2))
continue
else: # Don't
continue
print(total)