summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--2019/day02.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/2019/day02.c b/2019/day02.c
index 411762f..c574b57 100644
--- a/2019/day02.c
+++ b/2019/day02.c
@@ -1,10 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
-int main(void) {
-	int v[1024] = {0};
-	for (int i = 0; EOF != scanf("%d,", &v[i]); ++i);
-	v[1] = 12;
-	v[2] = 2;
+#include <string.h>
+static void run(int *v) {
 	for (int i = 0; v[i] != 99; i += 4) {
 		switch (v[i]) {
 			break; case 1: v[v[i + 3]] = v[v[i + 1]] + v[v[i + 2]];
@@ -12,5 +9,25 @@ int main(void) {
 			break; default: abort();
 		}
 	}
+}
+int main(void) {
+	int a[1024] = {0};
+	for (int i = 0; EOF != scanf("%d,", &a[i]); ++i);
+	int v[1024];
+	memcpy(v, a, sizeof(v));
+	v[1] = 12;
+	v[2] = 2;
+	run(v);
 	printf("%d\n", v[0]);
+	for (int noun = 0; noun < 100; ++noun) {
+		for (int verb = 0; verb < 100; ++verb) {
+			memcpy(v, a, sizeof(v));
+			v[1] = noun;
+			v[2] = verb;
+			run(v);
+			if (v[0] != 19690720) continue;
+			printf("%d\n", 100 * noun + verb);
+			return 0;
+		}
+	}
 }
ca171dc3ee6ac24822bdd8c315997759&follow=1'>Clear edit buffer before running commandJune McEnroe 2022-02-20Show indicator in status when window has pending inputJune McEnroe 2022-02-20Use separate edit buffers for each IDJune McEnroe 2022-02-20Make sure new cap is actually larger than new lengthJune McEnroe 2022-02-20Remove unused mbs.len field from struct EditJune McEnroe 2022-02-19Remove unneeded includes in ui.cJune McEnroe 2022-02-19Reimplement tab completeJune McEnroe 2022-02-19Handle errors from editFn, etc.June McEnroe 2022-02-19Reimplement text macrosJune McEnroe 2022-02-19Factor out input handling to input.cJune McEnroe 2022-02-19Factor out window management to window.cJune McEnroe 2022-02-19Enable -Wmissing-prototypesJune McEnroe 2022-02-19Fix edit.[ch] license notice additional permissionsJune McEnroe 2022-02-19Run line editing testsJune McEnroe 2022-02-18Implement new line editing "library"June McEnroe 2022-02-18Simplify cursor positioning in inputJune McEnroe 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