+/AoC
advent of code
git clone https://git.julia.blue/+/AoC
5191eec
master
1from collections import deque 2from functools import reduce as fold 3 4table = {")" :3 ,"]" :57 ,"}" :1197 ,">" :25137 } 5othertable = {c :i + 1 for i ,c in enumerate (table )} 6match = {"(" :")" ,"{" :"}" ,"<" :">" ,"[" :"]" } 7total = 0 8scores = [] 9with open ("input" )as f : 10for line in f : 11stack = deque () 12skip = False 13for c in line .strip (): 14if c in match : 15stack .append (c ) 16else : 17off = stack .pop () 18if c != match [off ]: 19total += table [c ] 20skip = True 21break 22if skip : 23continue 24close = [match [c ]for c in stack ][::- 1 ] 25scores .append (fold (lambda a ,c :5 * a + othertable [c ],close ,0 )) 26total ) 27sorted (scores )[len (scores )// 2 ])