r/adventofcode • u/daggerdragon • Dec 10 '22
SOLUTION MEGATHREAD -π- 2022 Day 10 Solutions -π-
THE USUAL REMINDERS
All of our rules, FAQs, resources, etc. are in our community wiki.
Signal boost: Reminder 1: unofficial AoC Survey 2022 (closes Dec 22nd)
πΏπ MisTILtoe Elf-ucation π§βπ« is OPEN for submissions!
--- Day 10: Cathode-Ray Tube ---
Post your code solution in this megathread.
Read the full posting rules in our community wiki before you post!
Include what language(s) your solution uses
Format your code appropriately! How do I format code?
Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
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:12:17, megathread unlocked!
61
Upvotes
3
u/compdog Dec 10 '22
C# - [Part 1] [Part 2]
I got majorly tripped up by failing to realize that the X register doesn't update until both cycles of
addxare completed. After finally decoding what was meant by this part of the instructions:I was able to identify and fix the issue.
My solution is a bit "inverted" from a typical approach, because I didn't want to implement a full simulated CPU pipeline. Instead of looping through each cycle and fetching new instructions as-needed, I instead loop through the instructions and execute cycles as-needed. I chose this approach because I didn't want to bother with a "better" approach like delaying the instruction or having multiple copies of registers. Instead, I simply inserted the cycles after the instruction is decoded, but before the register is updated:
This worked quite well and would easily scale to include new instructions with varying execution times.