22 lines
615 B
Python
22 lines
615 B
Python
import aocd
|
|
|
|
import operator
|
|
import functools
|
|
|
|
def parse(data):
|
|
op_table = {'+': operator.add, '*': operator.mul}
|
|
|
|
*nums, ops = (row.split() for row in data.strip().split('\n'))
|
|
|
|
nums = zip(*(map(int, row) for row in nums)) # zip(*l) <- ancient trick for transposing l; learned it from golfing :3
|
|
|
|
ops = (op_table[op] for op in ops)
|
|
return zip(ops, nums)
|
|
|
|
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='a', day=6, year=2025) |