diff options
author | June McEnroe <june@causal.agency> | 2020-12-15 00:06:58 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-12-15 00:06:58 -0500 |
commit | a56f3b726637e2140ab8d7ca2981649167f1ea70 (patch) | |
tree | bc41ff93d2e9d36a3e6bd8488222b25e69159f55 | |
parent | Rewrite day 14 to log all writes then sort them (diff) | |
download | aoc-a56f3b726637e2140ab8d7ca2981649167f1ea70.tar.gz aoc-a56f3b726637e2140ab8d7ca2981649167f1ea70.zip |
Solve day 15 part 1
-rw-r--r-- | 2020/day15.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/2020/day15.c b/2020/day15.c new file mode 100644 index 0000000..f5ee806 --- /dev/null +++ b/2020/day15.c @@ -0,0 +1,21 @@ +#include <stdio.h> +#include <stdlib.h> +int main(void) { + int nums[2048]; + int len = 0; + while (0 < scanf("%d,", &nums[len])) { + len++; + } + while (len < 2020) { + int last = nums[len-1]; + int next = 0; + for (int i = len - 2; i >= 0; --i) { + if (nums[i] == last) { + next = len - 1 - i; + break; + } + } + nums[len++] = next; + } + printf("%d\n", nums[len-1]); +} |