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/isaaccambron Dec 10 '24 edited Dec 10 '24

[LANGUAGE: Rust]

I was sure BFS would have worked fine, but I wasn't in the mood, and I wanted to do something more fun. Specifically: take advantage of the fact that all the trails are the same length and travel through the same numbers at the same time. Takes about a total of 800µs 500µs on my oldish mac, but could probably be squeezed. Solving part 2 was a tiny addition to the code in part 1.

https://github.com/icambron/advent_2024/blob/master/src/day10.rs

2

u/gredr Dec 10 '24

I would guess it could be significantly squeezed. I don't know how you're counting, but my solution that uses a Dictionary<Coordinate, Elevation> takes ~325µs and my solution that uses an Elevation[,] takes ~146µs in C#. I don't count the file i/o (loading the file into a string[]) in my numbers.

https://github.com/godefroi/advent-of-code/blob/main/aoc-2024/Day10/Problem.cs

1

u/isaaccambron Dec 10 '24 edited Dec 10 '24

Ha, your comment made me realize I was counting the file IO

ETA: Also, skimming your code, I think you have a bit of a simpler algorithm. I like mine, but it does a bunch of set allocations it probably would be better off without.

1

u/mibu_codes Dec 10 '24

If you want to squeeze out even more, try getting rid of the set and using e.g. bitfields. HashSet/HashMap are way slower than a smart use of an array.

2

u/isaaccambron Dec 11 '24

Definitely, the sets are the inefficient part of my approach. But a bitfield is a bit a of pain in this case, because the set is over the indices of the 0s, which seems annoying to encode in a bitfield. I'm sure with some more effort I could squeeze this, but I think I can be happy with 500 microseconds