-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10.py
53 lines (34 loc) · 819 Bytes
/
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
from lib import *
input = read_input(2021, 10)
lines = input.splitlines()
out = 0
for line in lines:
stack = []
for c in line:
if c in "([{<":
stack.append(c)
else:
x = stack.pop()
if x + c not in ["()", "[]", "{}", "<>"]:
out += {")": 3, "]": 57, "}": 1197, ">": 25137}[c]
break
else:
out += 0
print(out)
out = []
for line in lines:
stack = []
for c in line:
if c in "([{<":
stack.append(c)
else:
x = stack.pop()
if x + c not in ["()", "[]", "{}", "<>"]:
break
else:
s = 0
for c in reversed(stack):
s = s * 5 + " ([{<".index(c)
out.append(s)
out.sort()
print(out[len(out) // 2])