28 lines
722 B
Python
28 lines
722 B
Python
import aocd
|
|
|
|
import operator
|
|
import functools
|
|
|
|
def parse(data):
|
|
op_table = {'+': operator.add, '*': operator.mul}
|
|
|
|
cols = zip(*data.strip('\n').split('\n'))
|
|
|
|
problems = [[]]
|
|
for col in cols:
|
|
if any(c != ' ' for c in col):
|
|
# Not an empty line
|
|
problems[-1].append(col)
|
|
else:
|
|
# Empty line
|
|
problems.append([])
|
|
|
|
return ((op_table[p[0][-1]], [int(''.join(col[:-1])) for col in p]) for p in problems)
|
|
|
|
def main(data):
|
|
return sum(functools.reduce(f, nums) for f, nums in parse(data))
|
|
|
|
if __name__ == '__main__':
|
|
solution = main(aocd.get_data(day=6, year=2025))
|
|
print(solution)
|
|
aocd.submit(solution, part='b', day=6, year=2025) |