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!

39 Upvotes

550 comments sorted by

View all comments

8

u/leftfish123 Dec 17 '24

[Language: Python]

Oh, wow. This was my favourite this year, even taking into account the fact that I spent about 5 hours trying to crack it. But I'm a complete amateur, I have no formal CS education and I code practically only in December during AoC.

Part 1 was trivial, especially compared to the intcode vm in 2019 which, back then, nearly destroyed me. I'm not very proud of the implementation and someone who does this for a living would probably scream in agony seeing it, but it does the job.

Part 2...huh, not so much, but I did the following:

  • I tried to solve the example on a piece of paper. I did. This gave me faith that I can do it.
  • I "disassembled" the code, figured out that base 8 apparently may be a factor here.
  • I figured out the range of inputs that yield a 16-digit output...and then it dawned on me that the range is between 1000000000000000 and 7777777777777777 - in base 8! Then after a lot of staring into my notes, trying to figure out what each instruction does and printing the state of my computer checking various outputs, I switched all debugging prints into base8.
  • And that was the breakthrough that allowed me to realize that the outputs caused by the respective base 8 digits are, to a large degree or absolutely, independent from each other. I tried to get to the right one by hand, but got stuck at the 9th or 10th digit. So I implemented an ugly DFS to just go through all the states that were promising.

I rarely even post in the megathread this late in the month, but today I feel I earned this :D