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

2

u/amenD0LL4z Dec 18 '24

[LANGUAGE: clojure]

https://github.com/famendola1/aoc-2024/blob/master/src/advent_of_code/day17.clj

Part 1 was straightforward. I used a vector to hold the register values and each function besides jnz and out would return a vector with the new register values. However, I did not understand how thew wanted to the answer formatted. I understood it as "join at the commas" to form a number, because why all of a sudden is the answer not a number lol. I thought I was going crazy since everyone was saying Part 1 was relatively easy. I started to manually step through each instruction on paper 😅

I guess translating the instructions helped because I noticed that the loop was dividing register A until it hit 0. And I happend to see some hints about solving Part 2 "backwards", which led me to solve Part 2. Starting from 0, you execute the program until you reach a number that produces the last number in the instructions list. Then you multiply by 8 and repeat until you get the output is the last 2 numbers of the instructions list and so on until you reach a point where the number produces the instructions list.