From d4724b19e47b50a0ae0d732a7f6fc0cb8fdcba1a Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Mon, 2 Dec 2019 00:14:49 -0500 Subject: Solve day 2 part 1 --- 2019/day02.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 2019/day02.c (limited to '2019') 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 +#include +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]); +} -- cgit 1.4.1