My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add solution for 2024/03

+16
+16
2024/day03.py
··· 1 + import re 2 + import fileinput 3 + 4 + 5 + MUL_RE = r"mul\((\d+),(\d+)\)" 6 + DONT_DO_RE = r"don\'t\(\).*?(do\(\)|$)" # match a `do()` or end of string 7 + 8 + 9 + def count_muls(program): 10 + return sum(int(x) * int(y) for x, y in re.findall(MUL_RE, program)) 11 + 12 + 13 + program = ''.join(line.strip() for line in fileinput.input()) 14 + print("Part 1:", count_muls(program)) 15 + print("Part 2:", count_muls(re.sub(DONT_DO_RE, '', program))) 16 +