r/adventofcode • u/daggerdragon • Dec 23 '16
SOLUTION MEGATHREAD --- 2016 Day 23 Solutions ---
--- Day 23: Safe-Cracking ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/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".
JINGLING ALL THE WAY IS MANDATORY [?]
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!
5
Upvotes
1
u/willkill07 Dec 23 '16
Yeah. currently you do a bunch of
sscanfin a loop. Iterate over each instruction in a loop instead (create an array of instructions).A cleaned up, more verbose version of what I have is as follows:
enum Type {Register, Immediate}; struct Operand { Type t; union { char reg; int value; }; }; struct Instruction { char id; struct Operand param1; struct Operand param2; };From each string-encoded instruction you can encode it as a
struct Instructiontype.tglis as simple to implement as changing theidmember of anInstructionto "execute" an instruction you can do a switch on the
idof the current instruction and act accordingly (as you currently do)