Advent of Code 2021 Python Solution: Day 10
Viper
Posted on December 10, 2021
I forgot the time of the challenge but still managed to make it done. Stack came to the aid.
Part 1
data,data1=get_data(day=10)
table = {
")": 3,
"]": 57,
"}": 1197,
">": 25137}
pair = {"(":")","{":"}", "[":"]", "<":">"}
corruptions = []
rem = []
for i,r in enumerate(data):
stack = []
is_corr=False
for c in r:
if c in pair:
stack.append(pair[c])
elif stack.pop() != c:
print(f"Corrupted {c} at row {i}")
corruptions.append(c)
is_corr=True
break
if is_corr==False and len(stack)>0:
rem.append(stack)
corr = dict(Counter(corruptions))
sum([table[k]*v for k,v in corr.items()])
Part 2
mult = {")": 1,
"]": 2,
"}": 3,
">": 4}
all_total=[]
for row in rem:
s = 0
for i,c in enumerate(row):
s+=5**i*mult[c]
all_total.append(s)
at = sorted(all_total)
at[len(at)//2]
Why not read more?
- Gesture Based Visually Writing System Using OpenCV and Python
- Gesture Based Visually Writing System: Adding Visual User Interface
- Gesture Based Visually Writing System: Adding Virtual Animationn, New Mode and New VUI
- Gesture Based Visually Writing System: Add Slider, More Colors and Optimized OOP code
- Gesture Based Visually Writing System: A Web App
- Contour Based Game: Break The Bricks
- Linear Regression from Scratch
- Writing Popular ML Optimizers from Scratch
- Feed Forward Neural Network from Scratch
- Convolutional Neural Networks from Scratch
- Writing a Simple Image Processing Class from Scratch
- Deploying a RASA Chatbot on Android using Unity3d
- Naive Bayes for text classifications: Scratch to Framework
- Simple OCR for Devanagari Handwritten Text
💖 💪 🙅 🚩
Viper
Posted on December 10, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.