diff options
author | June McEnroe <june@causal.agency> | 2019-12-02 00:14:49 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-12-02 00:14:49 -0500 |
commit | d4724b19e47b50a0ae0d732a7f6fc0cb8fdcba1a (patch) | |
tree | 7c62462f64ed1b63d5cd359aa43ac38ef4a8f81f | |
parent | Solve day 1 part 2 (diff) | |
download | aoc-d4724b19e47b50a0ae0d732a7f6fc0cb8fdcba1a.tar.gz aoc-d4724b19e47b50a0ae0d732a7f6fc0cb8fdcba1a.zip |
Solve day 2 part 1
-rw-r--r-- | 2019/day02.c | 16 |
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]); +} |