day3 part2
This commit is contained in:
parent
60932a5324
commit
cb9cc445c0
@ -7,7 +7,6 @@ def part1(rows):
|
|||||||
total = 0
|
total = 0
|
||||||
r = re.compile(r'mul\(\d+,\d+\)')
|
r = re.compile(r'mul\(\d+,\d+\)')
|
||||||
for row in rows:
|
for row in rows:
|
||||||
print(row)
|
|
||||||
muls = r.findall(row)
|
muls = r.findall(row)
|
||||||
for m in muls:
|
for m in muls:
|
||||||
x, y = scanf("mul(%d,%d)", m)
|
x, y = scanf("mul(%d,%d)", m)
|
||||||
@ -18,7 +17,22 @@ def part1(rows):
|
|||||||
|
|
||||||
# @shared.profile
|
# @shared.profile
|
||||||
def part2(rows):
|
def part2(rows):
|
||||||
pass
|
total = 0
|
||||||
|
r = re.compile(r'(mul\(\d+,\d+\)|do\(\)|don\'t\(\))')
|
||||||
|
enabled = True
|
||||||
|
for row in rows:
|
||||||
|
muls = r.findall(row)
|
||||||
|
for m in muls:
|
||||||
|
if m == "don't()":
|
||||||
|
enabled = False
|
||||||
|
continue
|
||||||
|
if m == "do()":
|
||||||
|
enabled = True
|
||||||
|
continue
|
||||||
|
if enabled:
|
||||||
|
x, y = scanf("mul(%d,%d)", m)
|
||||||
|
total += x * y
|
||||||
|
print(total)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
1
2024/samples/day03.txt.part2
Normal file
1
2024/samples/day03.txt.part2
Normal file
@ -0,0 +1 @@
|
|||||||
|
xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))
|
Loading…
Reference in New Issue
Block a user