You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
734 B
31 lines
734 B
import numpy as np
|
|
from collections import deque
|
|
|
|
file = "inputs/day10.input"
|
|
lines = [x.decode().replace("\n", "") for x in open(file, "rb").readlines()]
|
|
|
|
match = {"<": ">", "(": ")", "[": "]", "{": "}"}
|
|
opening = ["<", "(", "[", "{"]
|
|
points = {">": 25137, ")": 3, "]": 57, "}": 1197}
|
|
|
|
|
|
def check_corruption(line):
|
|
stack = deque("")
|
|
for letter in line:
|
|
if letter in opening:
|
|
stack.append(letter)
|
|
else:
|
|
last_opening = stack.pop()
|
|
if letter != match[last_opening]:
|
|
return letter
|
|
return "0"
|
|
|
|
|
|
score = 0
|
|
for line in lines:
|
|
corruption_check = check_corruption(line)
|
|
if corruption_check != "0":
|
|
score += points[corruption_check]
|
|
|
|
print(score)
|