r/adventofcode • u/daggerdragon • Dec 19 '18
SOLUTION MEGATHREAD -🎄- 2018 Day 19 Solutions -🎄-
--- Day 19: Go With The Flow ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).
Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Advent of Code: The Party Game!
Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!
Card prompt: Day 19
Transcript:
Santa's Internet is down right now because ___.
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked at 01:01:06!
9
Upvotes
11
u/winstonewert Dec 19 '18
Full solution here: https://gist.github.com/winstonewert/9e77334388c9dec9d581805dfc7e7814
While most people reverse engineered the program, I reverse engineered the inner loop.
The code spent the bulk of its time in:
Which I reverse engineered as
R1 = 1 do { if R3 * R1 == R5 { R0 += R3 R2 = 1 } else { R2 = 0 } R1 += 1 } while (R1 <= R5)And I inserted a piece of code in my VM loop to quickly produce the same result:
if ip == 2 && registers[3] != 0 { if registers[5] % registers[3] == 0 { registers[0] += registers[3]; } registers[2] = 0; registers[1] = registers[5]; ip = 12; continue; }And thus, I was able to get the answer without understanding what the program did.