summary refs log tree commit diff homepage
path: root/2019
diff options
context:
space:
mode:
Diffstat (limited to '2019')
-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]);
+}