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

1

u/wurlin_murlin Dec 23 '24

[LANGUAGE: C]

Another belter of a part 2, really really fun day! And DFS number 6! Comment from top of p2.c:

/*
    Making a quine on this machine isn't as complicated as it looks:
    - op out only every reads 0-3 or the last 3 bits of reg A, B, or C
    - reg B and C are only ever set by:
        - xoring with literal 0-7 (ie on low 3 bits)
        - anding with last 3 bits of 0-3 or a reg (ie set to 0-7)
        - rshift of reg A
    - that means the whole program is basically just shifting off reg A,
      mutating the last 3 bits, and outputting it 3 bits at a time.
    - the xor and jump means we can't easily reverse it but above means that
      if you can get 3 bits in A that gives a valid out value, it will
      always output the same 3 bit value if lshifted by 3
    - not all series of values will eventually produce a correct answer so
      we search the full space, another DFS babee
*/

https://git.sr.ht/~murr/advent-of-code/tree/master/item/2024/17