r/adventofcode • u/Prestigious-Mood1711 • 3d ago
Visualization [2024 Day 18] [Kotlin] Visualization with GraphMateKT
Around 2 years ago, Advent of code inspired me to add vizualization capabillities to my GraphLibrary: GraphMateKT. Now, I'm starting a youtube series, showcaseing it's capabilities, by solving old AoC puzzles, and hopefully, new ones. I'm looking forward to AoC 2026! For now, here's a vizualization of a breath first search on a partially blocked and fully blocked grid!
38
Upvotes


4
u/RazarTuk 3d ago
As it would happen, I actually just reimplemented my solution for 2024 Day 18 in Kotlin, albeit in the context of working through past years and hitting 2016 Day 13. The algorithm's overkill for basically anything except 2024 Day 18 Part 2, but I actually used a fancy one called LPA*, which is tailor-made for Part 2. Basically, it's an adaptation of A* which adds some metadata, so that if you add a new wall, it only has to update things beyond it
If you're interested, I can get you pseudocode, so you can add it to your library
3
u/RazarTuk 3d ago
Pseudocode, if you want to add LPA* to your library:
Each node has both an expected distance and a reported distance. The reported distance corresponds to the "regular" distance in Dijkstra's algorithm, while the expected distance is the lowest possible reported distance based on any of its neighbors. The score for the priority queue is the lower of these values. If you want to add a heuristic, compare
min(expected, reported) + heuristic, but break ties withmin(expected, reported), as opposed to how you'd break ties with the heuristic in normal A*.queue.add_or_updateis shorthand for "Add this to the queue if it wasn't already there, or update its priority if it is". And instead of checking every node again, this will only re-process any nodes that are "behind" the new wall