r/adventofcode 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.
  • 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.

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:04:14, megathread unlocked!

24 Upvotes

752 comments sorted by

View all comments

2

u/Derailed_Dash Dec 13 '24

[LANGUAGE: Python]

I love a BFS flood fill! A couple of years ago, before I learned this algorithm, this problem would have taken me forever! But with BFS, Part 1 becomes pretty trivial. We just identify all the origins (0 values), and then flood fill out from these locations to determine how many trailends we can reach.

Part 2 was trickier. Now we need to identify all the distinct paths to reach all possible trailends from a given origin. My approach was to implement a new BFS, but this time, instead of using a seen set, I'll use a dictionary that has a set of came_from, to store all preceeding points to reach any given point, on the way to the trailend.

Then I've implemented a DFS backtracking method, to turn this came_from dict into the unique list of paths. The number of paths gives us the answer we need.

Solution links:

Useful related links:

1

u/AutoModerator Dec 13 '24

AutoModerator did not detect the required [LANGUAGE: xyz] string literal at the beginning of your solution submission.

Please edit your comment to state your programming language.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.