From a56f3b726637e2140ab8d7ca2981649167f1ea70 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Tue, 15 Dec 2020 00:06:58 -0500 Subject: Solve day 15 part 1 --- 2020/day15.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 2020/day15.c (limited to '2020') 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 +#include +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]); +} -- cgit 1.4.1