You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
858 B

2 years ago
lines = open("input.txt", 'r').read().splitlines()
di = {
2 years ago
('(', ')', 3, 1),
('[', ']', 57, 2),
('{', '}', 1197, 3),
('<', '>', 25137, 4)
2 years ago
}
2 years ago
score1 = 0
score2 = []
2 years ago
for l in lines:
stack = []
2 years ago
valid = True
2 years ago
for c in l:
if c == '(' or c == '[' or c == '{' or c == '<':
stack.append(c)
if c == ')' or c == ']' or c == '}' or c == '>':
match = [x for x in di if x[1] == c][0]
if stack.pop() != match[0]:
score1 += match[2]
2 years ago
valid = False
2 years ago
break
2 years ago
if valid:
if stack == []:
break
score = 0
while stack != []:
cha = stack.pop()
score = score * 5 + [x for x in di if x[0] == cha][0][3]
score2.append(score)
2 years ago
2 years ago
print(score1)
score2.sort()
print(score2[(int)(len(score2)/2)])