summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--2018/day19.c61
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;
externally. My goal with this library is to be able to implement vi mode. Since it operates on struct instances rather than globals, it might also be possible to give catgirl separate line editing buffers for each window, which would be a nice UX improvement. 2022-02-18Simplify cursor positioning in inputJune McEnroe Do some extra work by adding the portion before the cursor to the input window twice, but simplify the interaction with the split point. This fixes the awkward behaviour when moving the cursor across colour codes where the code would be partially interpreted up to the cursor. 2022-02-18Fix M-f orderingJune McEnroe 2022-02-12Move sandman build to scripts/MakefileJune McEnroe 2022-02-12Use compat_readpassphrase.c on LinuxJune McEnroe 2022-02-12Copy RPP defines from oconfigureJune McEnroe