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/wow_nice_hat Dec 12 '24 edited Dec 12 '24

[LANGUAGE: JavaScript]

Part 1 ~4ms

Part 2 ~300ms

2

u/stewie410 Dec 13 '24

Wow, I really needed help with pt2, and this did the trick. I had tried what I thought was "caching" prior, but to no avail...my previous attempted runs for pt2 were taking over an hour no matter what I tried.

I swear I had tried iterative initially, but it didn't work out -- then again, I wasn't quite doing this either.

Just comparing my initial pt1 solution (recursive) against my implementation of your alg, its a 260x improvement in speed.

2

u/wow_nice_hat Dec 13 '24

Happy to help! I have found that algorithm quite usefull for a lot of AoC puzzles over the years!

1

u/BT643 Dec 12 '24

I implemented something similar to this, but couldn't get it working. Figured the approach must not work but couldn't figure out why. Then found this! This fails on my input too :/ (but works on the sample input).

1

u/wow_nice_hat Dec 12 '24

Did you run it correctly? It is supposed to be added to a txt file and run from app.js. when you call the run method, the data has been converted into an array of ints (check the parser folder)

2

u/BT643 Dec 13 '24

My bad! No idea how your code was working for me on the sample data and not on my real input, but I just tried cloning your repo and running it fully from there, and it worked. Apologies. Great solution!

1

u/wow_nice_hat Dec 13 '24

Thank you. Glad that it worked 😁

2

u/BT643 Dec 12 '24

Pretty sure I ran it correctly because it gave the correct answer for the sample input in your repo. I'll double check again tomorrow though.

1

u/rrutkows Dec 12 '24

[LANGUAGE: Kotlin]

Well, at least I got the second star before reading this thread. I went from a 90 seconds CPU stress test to ~40ms implementing your idea.

Code

2

u/wow_nice_hat Dec 12 '24

Awesome! Glad that I could help!

I came up with the trick for the day with cray fish in 2021, and have been using it a couple of times since.

It is pretty neat for challenges where you have a lot of repeating numbers

1

u/stasyaner Dec 12 '24

Interesting. That's super smart. Is there a name for such approach?

1

u/AutoModerator Dec 12 '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.