summary refs log tree commit diff homepage
path: root/2019
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-12-02 00:14:49 -0500
committerJune McEnroe <june@causal.agency>2019-12-02 00:14:49 -0500
commitd4724b19e47b50a0ae0d732a7f6fc0cb8fdcba1a (patch)
tree7c62462f64ed1b63d5cd359aa43ac38ef4a8f81f /2019
parentSolve day 1 part 2 (diff)
downloadaoc-d4724b19e47b50a0ae0d732a7f6fc0cb8fdcba1a.tar.gz
aoc-d4724b19e47b50a0ae0d732a7f6fc0cb8fdcba1a.zip
Solve day 2 part 1
Diffstat (limited to '')
-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]);
+}