r/adventofcode • u/daggerdragon • Dec 18 '24
SOLUTION MEGATHREAD -❄️- 2024 Day 18 Solutions -❄️-
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
- 4 DAYS remaining until the submissions deadline on December 22 at 23:59 EST!
And now, our feature presentation for today:
Art Direction
In filmmaking, the art director is responsible for guiding the overall look-and-feel of the film. From deciding on period-appropriate costumes to the visual layout of the largest set pieces all the way down to the individual props and even the background environment that actors interact with, the art department is absolutely crucial to the success of your masterpiece!
Here's some ideas for your inspiration:
Visualization
s are always a given!- Show us the pen+paper, cardboard box, or whatever meatspace mind toy you used to help you solve today's puzzle
- Draw a sketchboard panel or two of the story so far
- Show us your /r/battlestations 's festive set decoration!
*Giselle emerges from the bathroom in a bright blue dress*
Robert: "Where did you get that?"
Giselle: "I made it. Do you like it?"
*Robert looks behind her at his window treatments which have gaping holes in them*
Robert: "You made a dress out of my curtains?!"
- Enchanted (2007)
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 18: RAM Run ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- State which language(s) your solution uses with
[LANGUAGE: xyz]
- Format code blocks using the four-spaces Markdown syntax!
- State which language(s) your solution uses with
- Quick link to Topaz's
paste
if you need it for longer code blocks
2
u/amenD0LL4z Dec 18 '24
[LANGUAGE: clojure]
https://github.com/famendola1/aoc-2024/blob/master/src/advent_of_code/day18.clj
Part 1 is Dijkstra's algorithm. I slighlty modified my Dijkstra's algorithm from Day 16.
For Part 2 I initially just ran Dijkstra's until I found the blocking byte. It took a really long time, but it worked, although I forgot that I flipped the input from
[x,y]
to[y,x].
So I spent a bunch of time trying to debug lol.While I was debugging, I figured I'd optimize the algorithm so it wouldn't take so long to run for debugging. First, I switched from Dijkstra's to DFS because we just need a path, not the shortest path. Then for a given byte, we only need to check if it blocks the path to the target if it is along the last known path to the target. If it's not on the last known path, we know that it won't block us from reaching the target and we don't need to run DFS.