summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-12-10 00:14:43 -0500
committerJune McEnroe <june@causal.agency>2020-12-10 00:14:43 -0500
commit3b468ed257608d13345a6a7c7a449216f374c4b8 (patch)
treed09da09fd7caad9a31085683cf31d4a5d62f2a82
parentSolve day 9 part 2 (diff)
downloadaoc-3b468ed257608d13345a6a7c7a449216f374c4b8.tar.gz
aoc-3b468ed257608d13345a6a7c7a449216f374c4b8.zip
Solve day 10 part 1
Trivial??
Diffstat (limited to '')
-rw-r--r--2020/day10.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/2020/day10.c b/2020/day10.c
new file mode 100644
index 0000000..789f2b1
--- /dev/null
+++ b/2020/day10.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <stdlib.h>
+static int compar(const void *_a, const void *_b) {
+	const int *a = _a;
+	const int *b = _b;
+	return *a - *b;
+}
+int main(void) {
+	int list[256];
+	int len = 0;
+	while (EOF != scanf("%d\n", &list[len])) {
+		len++;
+	}
+	list[len++] = 0;
+	qsort(list, len, sizeof(int), compar);
+	list[len] = list[len-1] + 3;
+	len++;
+	int j1 = 0, j3 = 0;
+	for (int i = 1; i < len; ++i) {
+		if (list[i] - list[i-1] == 1) j1++;
+		if (list[i] - list[i-1] == 3) j3++;
+	}
+	printf("%d\n", j1 * j3);
+}