Member-only story
Advent Of Code 2021 — Syntax Scoring — Puzzle 10
Hello ! I’m Xavier Jouvenot and here is the 10th part of a long series on Advent Of Code 2021.
For this new post, we are going to solve the problem from the 10th December 2021, named “Syntax Scoring”. The solution I will propose in C++, but the reasoning can be applied to other languages.
Self promotion: Here are a few social networks where you can follow me and check my work as a programmer and a writer 😉
Personal blog, Twitter, Dev.to, CodeNewbie, Medium, GitHub
Part 1
The Problem
The full version of this problem can be found directly on the Advent of Code website, I will only describe the essence of the problem here:
Our submarine wants to give us some information, but the navigation subsystem is broken and gives us a wonderful message:
Syntax error in navigation subsystem on line: all of them
We learn that navigation subsystem syntax is made of several lines containing chunks, and each chunk must be open and close with one of four legal pairs of matching characters: ‘(‘ and ‘)’, ‘{‘ and ‘}’, ‘[‘ and ‘]’, ‘<‘ and ‘>’. A chunk can contains several chunks, and one chunk can follow another one, but one chunk can not start inside one chunk and finish in another one.
We can, for example, have a navigation subsystem looking like:
[({(<(())[]>[[{[]{<()<>>…