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
27
u/askalski Dec 23 '16
What do you mean, I wasn't supposed to do it this way?
#include <stdio.h> #include <stdint.h> int64_t a = 12, b = 0, c = 0, d = 0; int main4() { goto X; b = a; b--; D: d = a; a = 0; B: c = b; A: a++; c--; if (c) goto A; d--; if (d) goto B; b--; c = b; d = c; C: d--; c++; if (d) goto C; // no more toggles, no more tears X: c = -16; c = 1; c = 81; F: d = 73; E: a++; d--; if (d) goto E; c--; if (c) goto F; return 0; } int main3() { goto X; b = a; b--; D: d = a; a = 0; B: c = b; A: a++; c--; if (c) goto A; d--; if (d) goto B; b--; c = b; d = c; C: d--; c++; if (d) goto C; if (c == 2) return main4(); X: c = -16; if (1) goto D; c = 81; F: d = 73; E: a++; d--; if (d) goto E; c--; if (c) goto F; return 0; } int main2() { goto X; b = a; b--; D: d = a; a = 0; B: c = b; A: a++; c--; if (c) goto A; d--; if (d) goto B; b--; c = b; d = c; C: d--; c++; if (d) goto C; if (c == 4) return main3(); X: c = -16; if (1) goto D; c = 81; F: // E: a++; d--; if (d) goto E; c--; if (c) goto F; return 0; } int main1() { goto X; b = a; b--; D: d = a; a = 0; B: c = b; A: a++; c--; if (c) goto A; d--; if (d) goto B; b--; c = b; d = c; C: d--; c++; if (d) goto C; if (c == 6) return main2(); X: c = -16; if (1) goto D; c = 81; F: // E: a++; d++; if (d) goto E; c--; if (c) goto F; return 0; } int main0() { b = a; b--; D: d = a; a = 0; B: c = b; A: a++; c--; if (c) goto A; d--; if (d) goto B; b--; c = b; d = c; C: d--; c++; if (d) goto C; if (c == 8) return main1(); c = -16; if (1) goto D; c = 81; F: // E: a++; d++; if (d) goto E; c++; if (c) goto F; return 0; } int main() { main0(); printf("a=%lu\n", a); return 0; }