diff options
author | June McEnroe <june@causal.agency> | 2018-12-21 07:01:23 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2018-12-21 07:01:23 -0500 |
commit | 43f93dd64b9d3a17e5256f0e90a02cb7699808b9 (patch) | |
tree | ec30dae7d4c59d315bf72c22243981a3a0e388c0 /2018/day19.c | |
parent | Solve day 19 part 2 (diff) | |
download | aoc-43f93dd64b9d3a17e5256f0e90a02cb7699808b9.tar.gz aoc-43f93dd64b9d3a17e5256f0e90a02cb7699808b9.zip |
Generalize day 19 solution
Diffstat (limited to '')
-rw-r--r-- | 2018/day19.c | 61 |
1 files changed, 12 insertions, 49 deletions
diff --git a/2018/day19.c b/2018/day19.c index eed25e1..d581f6b 100644 --- a/2018/day19.c +++ b/2018/day19.c @@ -111,57 +111,20 @@ int main(void) { } printf("%u\n", cpu.r[0]); - /* - 00: addi ip 16 ip goto 17 - 01: seti 1 _ r5 r5 = 1 - 02: seti 1 _ r3 r3 = 1 - 03: mulr r5 r3 r2 r2 = r5 * r3 - 04: eqrr r2 r4 r2 r2 = (r2 == r4) - 05: addr r2 ip ip if r2 goto 7 else goto 6 - 06: addi ip 1 ip goto 8 - 07: addr r5 r0 r0 r0 += r5 - 08: addi r3 1 r3 r3 += 1 - 09: gtrr r3 r4 r2 r2 = (r3 > r4) - 10: addr ip r2 ip if r2 goto 12 else goto 11 - 11: seti 2 _ ip goto 3 - 12: addi r5 1 r5 r5 += 1 - 13: gtrr r5 r4 r2 r2 = (r5 > r4) - 14: addr r2 ip ip if r2 goto 16 else goto 15 - 15: seti 1 _ ip goto 2 - 16: mulr ip ip ip halt - 17: addi r4 2 r4 r4 += 2 - 18: mulr r4 r4 r4 r4 *= r4 - 19: mulr ip r4 r4 r4 *= 19 - 20: muli r4 11 r4 r4 *= 11 - 21: addi r2 5 r2 r2 += 5 - 22: mulr r2 ip r2 r2 *= 22 - 23: addi r2 12 r2 r2 += 12 - 24: addr r4 r2 r4 r4 += r2 - 25: addr ip r0 ip if r0 goto 27 else goto 26 - 26: seti 0 _ ip goto 1 - 27: setr ip _ r2 r2 = 27 - 28: mulr r2 ip r2 r2 *= 28 - 29: addr ip r2 r2 r2 += 29 - 30: mulr ip r2 r2 r2 *= 30 - 31: muli r2 14 r2 r2 *= 14 - 32: mulr r2 ip r2 r2 *= 32 - 33: addr r4 r2 r4 r4 += r2 - 34: seti 0 _ r0 r0 = 0 - 35: seti 0 _ ip goto 1 - */ - -#if 0 - uint sum = 0; - uint big = 10551358; - for (uint a = 1; a <= big; a++) { - for (uint b = 1; b <= big; b++) { - if (a * b == big) sum += a; - } + cpu = (struct CPU) { + .ip = cpu.ip, + .r = { 1, 0, 0, 0, 0, 0 }, + }; + while (cpu.r[cpu.ip] != 1) { + struct Ins ins = prog[cpu.r[cpu.ip]]; + cpu = Ops[ins.op].fn(cpu, ins.a, ins.b, ins.c); + cpu.r[cpu.ip]++; + } + uint big = 0; + for (uint i = 0; i < 6; ++i) { + if (cpu.r[i] > big) big = cpu.r[i]; } - printf("%u\n", r0); -#endif - uint big = 10551358; uint sum = 1 + big; for (uint f = 2; big > 1; ++f) { if (big % f) continue; |