Created
December 10, 2021 05:24
-
-
Save albertein/6d0c5eba548182c6cd3ef3370e2f85f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scores = { | |
')': 3, | |
']': 57, | |
'}': 1197, | |
'>': 25137 | |
} | |
expected = { | |
'(': ')', | |
'[': ']', | |
'{': '}', | |
'<': '>' | |
} | |
def score(line): | |
stack = [] | |
for char in line: | |
if char in expected.keys(): | |
stack.append(char) | |
else: | |
if char == expected[stack[-1]]: | |
stack.pop() | |
else: | |
return scores[char] | |
return 0 | |
if __name__ == '__main__': | |
with open('input.txt') as data: | |
total_score = 0 | |
for line in data: | |
line = line.strip() | |
total_score += score(line) | |
print(total_score) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment