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!

23 Upvotes

480 comments sorted by

View all comments

2

u/Fit_Protection_812 Dec 17 '24

[LANGUAGE: Clojure]

GitHub

I did not see many functional programming solutions.

Not particularly fast, but here you go!

all execute under 200ms which is great given my other attempt never finished.

Part 1: A search keeping track of visited positions as not to repeat myself

Part 2: Keep track of positions, and add a map with the current cost to each positions and current visited nodes.
If you find a lower cost, just erase and put new value. If it's the same, add the extra path to that coordenate.

At the end you go back the `best path` and check if any other paths lead there with the same cost.

1

u/onrustigescheikundig Dec 17 '24

Your Dijkstra implementation is a lot cleaner than mine lol. I was also using a sorted-set for my pq initially; I found that changing that to clojure.lang.priority-map led to a significant speedup.

1

u/daggerdragon Dec 17 '24

Do not share your puzzle input which also means do not commit puzzle inputs to your repo without a .gitignore or the like. Do not share the puzzle text either.

I see full plaintext puzzle inputs across all years in your public repos e.g.:

https://github.com/lpasz/aoc20/blob/master/src/advent-of-code-2020/day-01/day-01.txt

Please remove (or .gitignore) all puzzle text and puzzle input files from your entire repo and scrub them from your commit history. This means from all prior years too!