16 lines
401 B
Python
16 lines
401 B
Python
|
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')
|