Day 10
This commit is contained in:
17
day10/part1.py
Normal file
17
day10/part1.py
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
lines = (x.strip() for x in open("input.txt"))
|
||||
|
||||
cnt = 0
|
||||
OPEN, CLOSE, PENALTY = "([{<", ")]}>", [3, 57, 1197, 25137]
|
||||
MAP_CLOSE, MAP_PENALTY = dict(zip(OPEN, CLOSE)), dict(zip(CLOSE, PENALTY))
|
||||
for line in lines:
|
||||
stack = []
|
||||
for char in line:
|
||||
if char in OPEN:
|
||||
stack.append(char)
|
||||
elif MAP_CLOSE[stack.pop()] != char:
|
||||
cnt += MAP_PENALTY[char]
|
||||
break
|
||||
|
||||
print(cnt)
|
||||
Reference in New Issue
Block a user