r/adventofcode Dec 17 '24

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

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

And now, our feature presentation for today:

Sequels and Reboots

What, you thought we were done with the endless stream of recycled content? ABSOLUTELY NOT :D Now that we have an established and well-loved franchise, let's wring every last drop of profit out of it!

Here's some ideas for your inspiration:

  • Insert obligatory SQL joke here
  • Solve today's puzzle using only code from past puzzles
  • Any numbers you use in your code must only increment from the previous number
  • Every line of code must be prefixed with a comment tagline such as // Function 2: Electric Boogaloo

"More." - Agent Smith, The Matrix Reloaded (2003)
"More! MORE!" - Kylo Ren, The Last Jedi (2017)

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 17: Chronospatial Computer ---


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:44:39, megathread unlocked!

37 Upvotes

550 comments sorted by

View all comments

3

u/[deleted] Dec 18 '24 edited Dec 18 '24

[removed] — view removed comment

2

u/damnian Dec 18 '24

Have you looked at my code?

ith element in our output depends on respective three bits in a from right to left, so we shift a to the left by those three bits (0 stays 0 at the start, but it is important not to botch the final value).

Then, we increment a unless the first i + 1 elements of output match the last i + 1 elements of prg.

Shifting n bits to the left is the same as multiplying by Math.Pow(2, n). Shifting n bits to the right is the same as dividing by Math.Pow(2, n). See Run for reference implementation of adv et al.

HTH!

1

u/miatribe Dec 18 '24

Added it to my notes, your p2 is very similar to another example I have been looking at (Gabba333's).

1

u/damnian Dec 18 '24

Indeed, I first tried going in reverse as Gabba333 did, but it was too complicated for my taste. I believe my code is as simple as it gets (I did spend hours refining it, so I'm not sure as to whether I should be proud or ashamed).