-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10.py
60 lines (48 loc) · 1.32 KB
/
10.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import fileinput
input = [l.strip() for l in fileinput.input()]
invalid = []
pointsCorrupted = 0
pointsIncomplete = []
incompletePunctation = {
'(': 1,
'[': 2,
'{': 3,
'<': 4,
}
for l in input:
stack = []
corrupted = False
for char in l:
if char == '{' or char == '(' or char == '<' or char == '[':
stack.append(char)
elif char == '}':
if stack.pop() != '{':
invalid.append('}')
corrupted = True
break
elif char == ')':
if stack.pop() != '(':
invalid.append(')')
corrupted = True
break
elif char == '>':
if stack.pop() != '<':
corrupted = True
pointsCorrupted += 25137
break
elif char == ']':
if stack.pop() != '[':
pointsCorrupted += 57
corrupted = True
break
else:
print('invalid character', char)
# 2
if not corrupted > 0:
print(stack)
points = 0
for char in reversed(stack):
points = points * 5 + incompletePunctation[char]
pointsIncomplete.append(points)
print(pointsCorrupted)
print(sorted(pointsIncomplete)[int(len(pointsIncomplete)/2)])