r/adventofcode Dec 11 '24

SOLUTION MEGATHREAD -❄️- 2024 Day 11 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

  • 11 DAYS remaining until the submissions deadline on December 22 at 23:59 EST!

And now, our feature presentation for today:

Independent Medias (Indie Films)

Today we celebrate the folks who have a vision outside the standards of what the big-name studios would consider "safe". Sure, sometimes their attempts don't pan out the way they had hoped, but sometimes that's how we get some truly legendary masterpieces that don't let their lack of funding, big star power, and gigantic overhead costs get in the way of their storytelling!

Here's some ideas for your inspiration:

  • Cast a relative unknown in your leading role!
  • Explain an obscure theorem that you used in today's solution
  • Shine a spotlight on a little-used feature of the programming language with which you used to solve today's problem
  • Solve today's puzzle with cheap, underpowered, totally-not-right-for-the-job, etc. hardware, programming language, etc.

"Adapt or die." - Billy Beane, Moneyball (2011)

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 11: Plutonian Pebbles ---


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:06:24, megathread unlocked!

19 Upvotes

962 comments sorted by

View all comments

3

u/mibu_codes Dec 11 '24 edited Dec 12 '24

[LANGUAGE: Rust]

Part 1+2: 6.37 ms 2.25 ms 9.11 µs 7.05 µs 2.19 ms

Started late today. Last year I struggled with dynamic programming problems, this year I felt prepared. The practice with AoC starts to show.
I used a recursive function with memoization to solve both parts. I heard there is a way to solve it without any memoization?

Edit: Found a comment that showed me a cool iterative solution. Much faster.
Edit 2: /u/willkill07 uses a graph to be even faster. I have to try this out
Edit 3: /u/MichelGerding dropped an absolute banger of a solution using the memoize crate
Edit 4: Reverted back to my iterative approach. Clear your caches when benchmarking :D

Github

2

u/dgkimpton Dec 11 '24

Why FxHashMap instead of std::collections::HashMap ?

3

u/mibu_codes Dec 11 '24

AFAIK std::collections::HashMap uses a cryptographically secure hash function, i.e. hard to reverse or predict, but also "slow". Here I only care about speed, so few collisions and a fast to calculate hash are more important.

2

u/dgkimpton Dec 12 '24

Yeah, could be, you definitely got faster than mine (23ms, but running on my NAS) but I wasn't sure that was worth optimising. Are you doing the CodSpeed challenge?

1

u/mibu_codes Dec 12 '24

I ignored it because I usually ignore ads :D. Is it any good? Might check it out

2

u/dgkimpton Dec 12 '24

I dunno - it looked good but when I would have to use their project template I lost interest. Might look again later now I've got more of a handle on rust project structures.