This commit is contained in:
Holly McFarland 2024-12-04 18:51:37 -05:00
parent 05174e324e
commit 232426c284
2 changed files with 31 additions and 0 deletions

15
day_03/part_a.py Normal file
View File

@ -0,0 +1,15 @@
import aocd
import re
def mul(a, b):
return int(a)*int(b)
def solve(data):
return sum(mul(*match) for match in re.findall(r'mul\((\d+),(\d+)\)', data))
if __name__ == '__main__':
solution = solve(aocd.get_data(year=2024, day=3))
print(solution)
aocd.submit(solution, year=2024, day=3, part='a')

16
day_03/part_b.py Normal file
View File

@ -0,0 +1,16 @@
import aocd
import re
def mul(a, b):
return int(a)*int(b)
def solve(data):
data = ''.join(segment.split("don't()")[0] for segment in data.split('do()'))
return sum(mul(*match) for match in re.findall(r'mul\((\d+),(\d+)\)', data))
if __name__ == '__main__':
solution = solve(aocd.get_data(year=2024, day=3))
print(solution)
aocd.submit(solution, year=2024, day=3, part='b')