aoc

My solutions for the Advent of Code
git clone https://git.tronto.net/aoc
Download | Log | Files | Refs | README

a.py (457B)


      1 import fileinput
      2 from functools import reduce
      3 from operator import mul
      4 
      5 a = []
      6 op = []
      7 with fileinput.input() as lines:
      8 	for line in lines:
      9 		t = line[:-1].split(' ')
     10 		if t[0] == '+' or t[0] == '*':
     11 			op = [x for x in t if x != '']
     12 		else:
     13 			a.append([int(x) for x in t if x != ''])
     14 
     15 def sol(a, op, i):
     16 	col = [a[j][i] for j in range(len(a))]
     17 	return sum(col) if op[i] == '+' else reduce(mul, col, 1)
     18 
     19 print(sum(sol(a, op, i) for i in range(len(a[0]))))