-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday10_task1.py
More file actions
52 lines (42 loc) · 1.26 KB
/
Copy pathday10_task1.py
File metadata and controls
52 lines (42 loc) · 1.26 KB
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
###############################################################################
# Day 10, Task 1 #
###############################################################################
import aoc_util
day = 10
data_str = """[({(<(())[]>[[{[]{<()<>>
[(()[<>])]({[<{<<[]>>(
{([(<{}[<>[]}>{[]{[(<()>
(((({<>}<{<{<>}{[]{[]{}
[[<[([]))<([[{}[[()]]]
[{[{({}]{}}([{[{{{}}([]
{<[[]]>}<{[{[{[]{()[[[]
[<(<(<(<{}))><([]([]()
<{([([[(<>()){}]>(<<{{
<{([{{}}[<[[[<>{}]]]>[]]"""
def score_sign(s):
if s == ")":
return 3
if s == "]":
return 57
if s == "}":
return 1197
if s == ">":
return 25137
def task(data_set: list[str]) -> int:
score = 0
for line in data_set:
chars = []
for i in line:
if i in "([<{":
chars.append(i)
else:
last = chars.pop()
if last == "(" and i != ")" \
or last == "[" and i != "]" \
or last == "{" and i != "}" \
or last == "<" and i != ">":
score += score_sign(i)
break
return score
aoc_util.run_with_data_str(task, data_str)
aoc_util.run_with_data_set(task, day)