summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-12-02 00:14:49 -0500
committerJune McEnroe <june@causal.agency>2020-11-22 00:14:26 -0500
commitfed971e1c004eab3a31c112f534ba1f9bfe8213e (patch)
tree9a01a4606dd61253f4f327aa9ef80b29d4def6ad
parentSolve day 1 part 2 (diff)
downloadaoc-fed971e1c004eab3a31c112f534ba1f9bfe8213e.tar.gz
aoc-fed971e1c004eab3a31c112f534ba1f9bfe8213e.zip
Solve day 2 part 1
-rw-r--r--2019/day02.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/2019/day02.c b/2019/day02.c
new file mode 100644
index 0000000..411762f
--- /dev/null
+++ b/2019/day02.c
@@ -0,0 +1,16 @@
+#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;
+	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]];
+			break; case 2: v[v[i + 3]] = v[v[i + 1]] * v[v[i + 2]];
+			break; default: abort();
+		}
+	}
+	printf("%d\n", v[0]);
+}