4
votes
Day 16: Reindeer Maze
Today's problem description: https://adventofcode.com/2024/day/16
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>
I was waiting for the annual pathfinding puzzle! I thought ahead and wrote a quick binary heap implementation before Advent of Code started this year, since the Jai compiler doesn't come with one and I knew I'd need one at some point. Today's puzzle was pretty straightforward as far as pathfinding puzzles go - the only tricky part was making the
seen
table work properly with part 2.Solution (Jai)
Binary heap
While exploring Pharo before AoC started, I did notice that there are some pathfinding algorithms programmed in. I actually found them because they seem to be where the generalized graph data structure is also contained. I didn't end up using them, but I might go back and try to re-solve with that approach to learn how those work.
I ended up storing the nodes as 3D points, with the regular position in x and y and the z storing the direction. I mostly did this to avoid having to write a new class with its own hash function, but it worked quite well. I've also gotten more comfortable adding methods to base classes: today I extended the
x@y
syntax for creating aPoint
tox@y@z
to create aG3DCoordinates
as well as addedatPoint:put:
forArray2D
which I had been wanting in previous days.Pharo Smalltalk Solution
Just the right problem to stop getting rusty with graph traversals.
Here my write-up for the last four days worth of problems.
This one was a lot of fun to puzzle through. Did I mention that I love pathfinding puzzles?
Rust (Part 1)
This is a fairly basic application of A* search. In retrospect, there was nothing really difficult about this, but I still managed to break it in seven hundred different ways because I thought I could code pathfinding up from scratch by now, instead of using a library or even reference material. Ah, the programmer virtue of hubris strikes again.
Rust (Part 2)
Part 2 was fairly easy, because all you have to do is wait until A* delivers you all shortest paths. By the properties of priority queues ordered by an adissable heuristic, you get all shortest paths before all longer paths. If your A* is subtly broken, though, you may need a long time to recover...
Benchmark
Pretty slow, because I have to lug around all those waypoints. :/