added day 10
This commit is contained in:
35
10/solve01.py
Normal file
35
10/solve01.py
Normal file
@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
score = {
|
||||
')': 3,
|
||||
']': 57,
|
||||
'}': 1197,
|
||||
'>': 25137,
|
||||
}
|
||||
closing = {
|
||||
'(': ')',
|
||||
'[': ']',
|
||||
'{': '}',
|
||||
'<': '>',
|
||||
}
|
||||
|
||||
|
||||
|
||||
def check_line_score(line):
|
||||
stack = ""
|
||||
for c in line:
|
||||
if c in '{([<':
|
||||
stack += c
|
||||
continue
|
||||
l = stack[-1]
|
||||
if c != closing[l]:
|
||||
return score[c]
|
||||
stack = stack[:-1]
|
||||
return 0
|
||||
|
||||
total = 0
|
||||
with open("input01.txt","r") as f:
|
||||
for line in f:
|
||||
total += check_line_score(line.strip())
|
||||
|
||||
print(total)
|
||||
Reference in New Issue
Block a user