From 752998b08a702de0d0dae222f49f264e83f0dee3 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Fri, 21 Dec 2018 14:34:39 +0100 Subject: [PATCH] Improve day21p2 Should now properly handle all inputs --- day21p2/main.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/day21p2/main.c b/day21p2/main.c index 8d243b2..f50e8a2 100644 --- a/day21p2/main.c +++ b/day21p2/main.c @@ -177,10 +177,15 @@ int main(int argc, char *argv[]) while (regs[ip] >= 0 && regs[ip] < instructions_len) { struct instr *instr = &instructions[regs[ip]]; - // Day 21 part 2 optimizations... - if (regs[ip] == 17) { - regs[5] >>= 8; - regs[ip] = 8; + // Day 21 part 2 optimization... + if (instr->i == INSTR_GTIR && instr->a == 0x100) { + reg_t *reg = ®s[instr->b]; + if (0x100 <= *reg) { + *reg >>= 8; + regs[ip] = 8; + } else { + regs[ip] = 28; + } continue; }