Compare commits
2 Commits
bb31161c80
...
e97762a3f7
Author | SHA1 | Date | |
---|---|---|---|
e97762a3f7 | |||
fa259faa2b |
@@ -10,6 +10,9 @@ for match in matches:
|
|||||||
total += int(match[0]) * int(match[1])
|
total += int(match[0]) * int(match[1])
|
||||||
print(total)
|
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
|
# 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
|
||||||
@@ -19,10 +22,6 @@ for match in matches:
|
|||||||
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
|
elif 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
|
|
||||||
else: # Don't
|
|
||||||
continue
|
|
||||||
print(total)
|
print(total)
|
Reference in New Issue
Block a user