Advertisement
Evoid-null

Advent of code 2021 day 10 part 2

Dec 10th, 2021
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. with open('input10.txt') as r:
  2.     l = r.read().split("\n")
  3. cl = {'(':')','[':']','{':'}','<':'>'}
  4.  
  5. def checkrow(i):
  6.     chunks = []
  7.     for j in i:
  8.         if j in cl:
  9.             chunks.append(j)
  10.         else:
  11.             if j != cl[chunks.pop()]:
  12.                 return -1
  13.     points = 0
  14.     for i in chunks[::-1]:
  15.         points = points*5+' ([{<'.index(i)
  16.     return points
  17.  
  18. scores = list(filter(lambda a: a != -1,[checkrow(i) for i in l]))
  19. print(sorted(scores)[len(scores)//2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement