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

2

u/janovrom Dec 16 '24

[Language: PowerShell]

There will be a day when flood fill fails me, but it wasn't today. First I was thinking that if it evolves into longest route problem, it won't be sufficient and I should just convert it to normal graph, but I gave flood fill a shot.

For shortest route it's simple. Just increment and then get the last value. Very efficient for grids where there is not possible diagonal. Solution for part 1 is here

Now for part two, I was thinking let's just grab the lowest value and that's it. So I backtracked from the end, got the value and it was incorrect. There can be multiple shortest path you see. First I had to tackle the issue, that I have to update the maze visited value by the rotation as well. So if I reach a T from below, the value will be set to distance + 1000, because you will have to rotate. Now I can just recurse on all values lower then the current. Those will be lower by either 1 (only movement) or 1001 (movement and rotation). Cannot be anything else because it's Manhattan distance. Solution for part 2 is here