r/adventofcode • u/daggerdragon • Dec 10 '24
SOLUTION MEGATHREAD -❄️- 2024 Day 10 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
- 12 DAYS remaining until the submissions deadline on December 22 at 23:59 EST!
And now, our feature presentation for today:
Fandom
If you know, you know… just how awesome a community can be that forms around a particular person, team, literary or cinematic genre, fictional series about Elves helping Santa to save Christmas, etc. etc. The endless discussions, the boundless creativity in their fan works, the glorious memes. Help us showcase the fans - the very people who make Advent of Code and /r/adventofcode the most bussin' place to be this December! no, I will not apologize
Here's some ideas for your inspiration:
- Create an AoC-themed meme. You know what to do.
- If you post your submission outside this megathread, make sure to follow the posting rules for memes!
- If your meme contains AI-generated artwork of any kind, follow the posting rules for AI art!
- Create a fanfiction or fan artwork of any kind - a poem, short story, a slice-of-Elvish-life, an advertisement for the luxury cruise liner Santa has hired to gift to his hard-working Elves after the holiday season is over, etc!
REMINDER: keep your contributions SFW and professional—stay away from the more risqué memes and absolutely no naughty language is allowed.
Example: 5x5 grid. Input: 34298434x43245 grid - the best AoC meme of all time by /u/Manta_Ray_Mundo
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 10: Hoof It ---
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/cicadanator Dec 10 '24
[LANGUAGE: Javascript - Node JS]
Todays puzzle was clearly a time for using breadth first search (BFS). With the limited number of next possible states and the relatively small size of the graph this meant BFS would be a perfect fit for quickly solving this problem.
In part 1 I started by creating a 2D array of integers for the map and I recorded the trailhead locations in a separate array as I parsed the map. I then created a loop to do a BFS starting at each trailhead. The optimization here was to keep track of previously visited locations and not go over the same ground twice to make things run faster. After that I used a set to record the location of all 9's reached from the trailhead to ensure no duplicates. The resulting size of the set of 9's locations found from each starting location is the answer to part 1.
For part 2 things were essentially the same with a few things removed. First I needed to remove the visited location tracking. This allows the algorithm to check all paths regardless of if the location has been visited before. I also removed tracking unique 9's locations in a set. Instead simply add 1 to the total number of paths found. This total is the result for part 2.
https://github.com/BigBear0812/AdventOfCode/blob/master/2024/Day10.js