summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--2020/day15.c21
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]);
+}