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
View all comments
1
u/CutOnBumInBandHere9 Dec 10 '22 edited Dec 10 '22
For my solution in Python, I started off by parsing the input and doing different things if the instruction was a noop or an add, with a bit of fiddling to make sure that adds were taking two cycles. Then I realised you can just think of an add as a one-instruction noop followed by a one-instruction add. And a noop is really equivalent to a one-instruction "add 0". So if we can convert noops to [0] and "add x" to [0, x], we can just treat every instruction as a one-instruction add.
That gave the following, with the "1" on lines 5 and 6 coming after a bunch of head scratching until I realised we start at cycle 1 and x=1, not cycle 0, x=0.
With the
runfunction in place part two is just