Created
December 18, 2021 01:04
-
-
Save loudambiance/b4968aa3cf5824e2843cc2ef780ebfaa to your computer and use it in GitHub Desktop.
This file contains 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
test = False | |
file = 'data/task10test.txt' if test else 'data/task10.txt' | |
with open(file) as f: | |
lines = f.read().splitlines() | |
opencharacters = ['[', '{','\'','<'] | |
score = 0 | |
for line in lines: | |
buffer = [] | |
for character in line: | |
tmp = character.replace('(','\'') | |
if tmp == "}": | |
i=1 | |
if tmp in opencharacters: | |
buffer.append(tmp) | |
else: | |
if len(buffer) > 0: | |
if ord(buffer[-1])+2 == ord(tmp): | |
buffer.pop() | |
continue | |
if character == ')': | |
score = score + 3 | |
if character == ']': | |
score = score + 57 | |
if character == '}': | |
score = score + 1197 | |
if character == '>': | |
score = score + 25137 | |
break | |
print(score) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment