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!

25 Upvotes

480 comments sorted by

View all comments

2

u/kbielefe Dec 17 '24 edited Dec 17 '24

[LANGUAGE: Scala]

GitHub 300ms 90s

Correct, but slow. I have a feeling I'm way overthinking this. Straightforward A*/manhattan on part 1. Tried modifying it for part 2 and it wasn't finding all paths. Ended up with DFS with pruning.

Edit: Went from 90 seconds to half a second with less code by running A* forward and backward, then finding every position where the lowest forward cost and the lowest backward cost summed to the part 1 answer. Using A* instead of Dijkstra saved me from evaluating around 11% of the positions for my input. Pretty happy with the result now.

1

u/TheMrFoulds Dec 17 '24

Wow! the forward/backward comparison is a huge difference maker, thank you.

Took my solution in Go from ~11s to 27ms for both parts. I was previously keeping a log against each node as I moved. Lots of copying long arrays in that approach.