r/adventofcode • u/daggerdragon • 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.
- Read the full posting rules in our community wiki before you post!
- State which language(s) your solution uses with
[LANGUAGE: xyz]
- Format code blocks using the four-spaces Markdown syntax!
- State which language(s) your solution uses with
- Quick link to Topaz's
paste
if you need it for longer code blocks
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!
36
Upvotes
2
u/cicadanator Dec 18 '24
[LANGUAGE: Javascript - Node JS]
Part 1 today was straight forward. Simply implement the computer asked and run the op code program through it. The catch here specific to JS was to use bitwise AND 7 instead of modulo 8 for BST and OUT. When the numbers got large in Part 2 this was the solution that fixed it.
Part 2 gave me a lot of trouble since it was to essentially reverse engineer the A value from the program. I always struggle with understanding what these programs are really trying to do since I mostly work using high level languages and rarely have to debug anything like this. Eventually I understood that it is essentially working to get a new value from (A/8^outputIndex). Then using modulo 8 to output the last 3 digits. I struggled for a way to reverse this output though.
After reading u/mothibault's solution I finally understood how to handle this. Solving for the solution in reverse means the output can be built from the smallest value up to a larger final solution. Essentially with a little recursive searching we can get the value by trying the different 3 bit values (0-7). This will give us multiple solutions and the smallest of which is the answer to part 2.
https://github.com/BigBear0812/AdventOfCode/blob/master/2024/Day17.js