43 lines
972 B
Python
Executable File
43 lines
972 B
Python
Executable File
#!/usr/bin/env python3
|
|
from useful import *
|
|
|
|
def parseline(s):
|
|
return s
|
|
return [int(c) for c in s]
|
|
return [int(x) for x in s.strip().split(',')]
|
|
|
|
with open(0) as f:
|
|
|
|
L = [parseline(l) for l in lines(f)]
|
|
total = 0
|
|
d = {
|
|
')': 3,
|
|
']': 57,
|
|
'}': 1197,
|
|
'>': 25137,
|
|
}
|
|
inc = {
|
|
'(': 1,
|
|
'[': 2,
|
|
'{': 3,
|
|
'<': 4,
|
|
}
|
|
fixscores = []
|
|
for l in L:
|
|
fixtotal = 0
|
|
for i in range(len(l)):
|
|
for p in '{} <> [] ()'.split():
|
|
l = l.replace(p, '')
|
|
|
|
lincomplete = l # save this
|
|
for p in '{ < [ ('.split():
|
|
l = l.replace(p, '')
|
|
if not l: # possibly incomplete
|
|
fixscores.append(reduce(lambda acc, c: acc * 5 + inc[c], lincomplete[::-1], 0))
|
|
continue
|
|
total += d[l[0]]
|
|
|
|
print( total)
|
|
print(sorted(fixscores)[len(fixscores)//2])
|
|
|