5
votes
Day 20: Donut Maze
Today's problem description: https://adventofcode.com/2019/day/20
Join the Tildes private leaderboard! You can do that on this page, by entering join code 730956-de85ce0c
.
Please post your solutions in your own top-level comment. Here's a template you can copy-paste into your comment to format it nicely, with the code collapsed by default inside an expandable section with syntax highlighting (you can replace python
with any of the "short names" listed in this page of supported languages):
<details>
<summary>Part 1</summary>
```python
Your code here.
```
</details>
Having done day 18 made this a good deal easier.
Part 1
The trickiest bit was really just parsing the input and detecting the labels correctly. I ended up scanning over the map and looking for uppercase letters, then checking all the neighbors to see if I could find both a second letter and an open/walkable '.' tile, which would be the portals actual location. Once I had all the labels, I could link up the pairs in a table and use that in my tile neighbors method.
A simple BFS search worked well enough to find the solution.
Part 2
This was also pretty straightforward, but again managing the portals themselves was rather tricky, detecting whether a portal lead "in" or "out" kept failing and causing the pathfinder to get lost down infinite one-way holes. Eventually it turned out that I wasn't accounting for the whitespace in the margins of the input correctly, and my map thought its width was much less than it actually was.
I updated the solver to work in three dimensions, and changed the neighbors method to return portal neighbors as either one step lower or higher.
Once I fixed that, a simple BFS was still too slow, so I switched to A* and had a quick solution. My solver is still examining every tile individually, but it runs in about 1s on my input.
Interestingly, on the second sample, my solver does get stuck with too many different paths, so I want to go back and fix it with a smarter approach.
Similar to Day 18, it should be possible to build a map of which portals are directly connected to which other portals, and then do a graph search over that to determine the best order to traverse the portals in.
Day 20 - Crystal