r/adventofcode • u/musifter • Apr 20 '26
Other [2018 Day 20] In Review (A Regular Map)
Today we find ourselves suddenly inside the newly built North Pole complex, which is a maze.
This one was particularly fun. Instead of abusing regex to get an answer, we're given a big regex and asked to understand its extent. Which is the description of the maze as relative directions, including branches (and even empty branches like (NEWS|)). The regex in my input does fully visit every room of a 100x100 maze, starting just off the center.
Not that I bothered with walls and doors like in the examples... I just did the rooms and trusted it was a maze. I did a recursive descent parser on the parenthesized expression. Tracking the coordinates visited, length, and depth. Of particular interest are those empty branches... the other part is always some path that doubles back to the same spot (as seen in the example text with NEWS, WNSE and SWEN). Basically tracing out a dead-end before moving things further along. It makes sure that everything got covered.
I always like writing a parser, and this one was interesting, with its connection to both regex and grids.
1
u/terje_wiig_mathisen Apr 22 '26
My solution here once again did it "by the book", with a Vec<Vec<u16>> (initialized to u16::MAX) to store the 500x500 cell maze, this needs half a megabyte of memory, but would be able to handle multiply-connected paths during the BFS traversal. Runtime 2 ms on Surface.
2
u/DelightfulCodeWeasel Apr 20 '26 edited Apr 20 '26
I did the facility exploration as a search queue after some preprocessing on the regex. For every '(' I store both the pattern index of the closing ')' and the pattern index for each of the branch choices:
Probably going to have to re-think that for the memory constrained version though, there are just over 100,000 unique states explored which is going to be a minimum of
600kb400kb.For my input there are just over 1,000 open brackets, so an explicit stack on a recursive descent parser should fit okay. What was your runtime like?