summary refs log tree commit diff homepage
path: root/2020
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-12-15 00:06:58 -0500
committerJune McEnroe <june@causal.agency>2020-12-15 00:06:58 -0500
commita56f3b726637e2140ab8d7ca2981649167f1ea70 (patch)
treebc41ff93d2e9d36a3e6bd8488222b25e69159f55 /2020
parentRewrite day 14 to log all writes then sort them (diff)
downloadaoc-a56f3b726637e2140ab8d7ca2981649167f1ea70.tar.gz
aoc-a56f3b726637e2140ab8d7ca2981649167f1ea70.zip
Solve day 15 part 1
Diffstat (limited to '2020')
-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]);
+}