Skip to content

Instantly share code, notes, and snippets.

@albertein
Created December 10, 2021 05:24
Show Gist options
  • Save albertein/6d0c5eba548182c6cd3ef3370e2f85f6 to your computer and use it in GitHub Desktop.
Save albertein/6d0c5eba548182c6cd3ef3370e2f85f6 to your computer and use it in GitHub Desktop.
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