-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdvent_of_code10.py
43 lines (38 loc) · 1.25 KB
/
Advent_of_code10.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
from typing import List,Dict
opposites = {'{':'}','[':']','(':')','<':'>'}
sytnax_error_reword = {')':1,']':2,'}':3,'>':4}
in_put = [r"[({(<(())[]>[[{[]{<()<>>",
r"[(()[<>])]({[<{<<[]>>(",
r"{([(<{}[<>[]}>{[]{[(<()>",
r"(((({<>}<{<{<>}{[]{[]{}",
r"[[<[([]))<([[{}[[()]]]",
r"[{[{({}]{}}([{[{{{}}([]",
r"{<[[]]>}<{[{[{[]{()[[[]",
r"[<(<(<(<{}))><([]([]()",
r"<{([([[(<>()){}]>(<<{{",
r"<{([{{}}[<[[[<>{}]]]>[]]",]
points = []
def get_data(path):
with open(path, 'r') as f:
in_ = []
for line in f.readlines():
in_.append(line.replace(" ","")[:-1])
return in_
in_put= get_data(r'D:\Coding\Python\handy\cases.txt')
for line in in_put:
queue : List[str] = []
for symbol in line:
if symbol not in opposites.keys() and symbol != queue[-1]:
break
elif symbol in opposites.keys():
queue.append(opposites[symbol])
else:
queue.pop()
else:
if len(queue) != 0:
temp_points = 0
for i in reversed(queue):
temp_points *= 5
temp_points += sytnax_error_reword[i]
points.append(temp_points)
print(sorted(points)[(len(points)-1)//2])