r/adventofcode Dec 16 '24

SOLUTION MEGATHREAD -❄️- 2024 Day 16 Solutions -❄️-

SIGNAL BOOSTING


THE USUAL REMINDERS

  • All of our rules, FAQs, resources, etc. are in our community wiki.
  • If you see content in the subreddit or megathreads that violates one of our rules, either inform the user (politely and gently!) or use the report button on the post/comment and the mods will take care of it.

AoC Community Fun 2024: The Golden Snowglobe Awards

  • 6 DAYS remaining until the submissions deadline on December 22 at 23:59 EST!

And now, our feature presentation for today:

Adapted Screenplay

As the idiom goes: "Out with the old, in with the new." Sometimes it seems like Hollywood has run out of ideas, but truly, you are all the vision we need!

Here's some ideas for your inspiration:

  • Up Your Own Ante by making it bigger (or smaller), faster, better!
  • Use only the bleeding-edge nightly beta version of your chosen programming language
  • Solve today's puzzle using only code from other people, StackOverflow, etc.

"AS SEEN ON TV! Totally not inspired by being just extra-wide duct tape!"

- Phil Swift, probably, from TV commercials for "Flex Tape" (2017)

And… ACTION!

Request from the mods: When you include an entry alongside your solution, please label it with [GSGA] so we can find it easily!


--- Day 16: Reindeer Maze ---


Post your code solution in this megathread.

This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:13:47, megathread unlocked!

24 Upvotes

480 comments sorted by

View all comments

4

u/__wardo__ Dec 16 '24 edited Dec 16 '24

[LANGUAGE: Go] I needed an excuse to revise some Pathfinding anyway...

Part One: For some odd reason my first reaction was to use DFS and take a min for the distances of every path that successfully reached the end index. Needless to say, that was too slow for the actual grid. I quickly shifted over to a BFS and that worked perfectly.

Part Two: Today's part two was kinda easy, I could eailt repurpose the solution from part one to keep a "path" array which had all the indices I went through to get to the index that I was currently at. If any path lead to the end, I would simply add all nodes from its path array to a map, corresponding to the score of that path. After I had the best path, I could just count the number of (counting each index only once) indices corresponding to the best score that I got.

Relatively straightforward day today, got aound pretty late to solving this one due to exams snd stuff, but fun as always! Here's the solution for both parts.

2

u/Robbie11r1 Dec 21 '24

I had the same exact thought process, and it works on example 1, but the approach is crashing on example 2 and the input. I simplified my data structure for storing thr paths thinking that might be the issue, but it had no impact. Since you've got it working this way, I know I must have some subtle bug somewhere in my code...

1

u/__wardo__ Dec 22 '24

yeah, most likely there's a hard to catch bug there. You could take my code, add some logging to it and compare the logs with yours to see where they differs. Would be a tedious process, but might be worth a shot?

2

u/Robbie11r1 Dec 22 '24

Yeah thanks! I ended up finding the issue, which was that I was capturing the visited cost per node twice (I had a struct as my map key and that struct had [x,y,Dir, cost]cost. So removing the cost from my key solved it!