-
Notifications
You must be signed in to change notification settings - Fork 0
/
10.py
executable file
·61 lines (53 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
61
#!/usr/bin/env python3
import numpy as np
with open('10.input', 'r') as f:
o = '([{<'
errors = {
')': 0,
']': 0,
'}': 0,
'>': 0
}
totals = []
for l in f.readlines():
trail = []
no_good = False
for b in l.strip('\n'):
s = 0
if b in o:
trail.append(b)
else:
got = trail.pop()
want = {
')': '(',
']': '[',
'}': '{',
'>': '<'
}[b]
if got != want:
errors[b] += 1
no_good = True
break
if no_good:
continue
trail.reverse()
completion = [
{
'(': ')',
'[': ']',
'{': '}',
'<': '>'
}[c] for c in trail]
c_score = 0
for c in completion:
c_score *= 5
c_score += {
')': 1,
']': 2,
'}': 3,
'>': 4
}[c]
totals.append(c_score)
result_a = errors[')'] * 3 + errors[']'] * 57 + errors['}'] * 1197 + errors['>'] * 25137
result_b = sorted(totals)[len(totals)//2]
print(result_a, result_b)