-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10a.py
More file actions
30 lines (21 loc) · 720 Bytes
/
Copy path10a.py
File metadata and controls
30 lines (21 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
f = open('./input/10.txt')
line = f.readline()
scores = {')': 3, ']': 57, '}': 1197, '>': 25137}
total_score = 0
while line != '':
stack = []
for c in line:
if c == '\n': break # oh \n, thou heartless bastard
if c in '([{<':
stack.append(c)
else: # c is a closing bracket
opening = stack.pop()
if opening == '(' and c == ')' or \
opening == '[' and c == ']' or \
opening == '{' and c == '}' or \
opening == '<' and c == '>': continue
# opening and closing brackets don't match
total_score += scores[c]
break
line = f.readline()
print(total_score)