summary refs log tree commit diff homepage
path: root/2020
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-12-06 00:15:38 -0500
committerJune McEnroe <june@causal.agency>2020-12-06 00:15:38 -0500
commit40ff7ef333e8889b386bc79b1a7eddf2d9145419 (patch)
tree5c173cae94dc3913adb4aefc60d4ecd551851672 /2020
parentSolve day 5 part 2 (diff)
downloadaoc-40ff7ef333e8889b386bc79b1a7eddf2d9145419.tar.gz
aoc-40ff7ef333e8889b386bc79b1a7eddf2d9145419.zip
Solve day 6 part 1
Diffstat (limited to '')
-rw-r--r--2020/day06.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/2020/day06.c b/2020/day06.c
new file mode 100644
index 0000000..07c40a3
--- /dev/null
+++ b/2020/day06.c
@@ -0,0 +1,21 @@
+#include <stdio.h>
+#include <stdlib.h>
+int main (void) {
+	size_t cap = 0;
+	char *buf = NULL;
+	unsigned groups[512] = {0};
+	for (int i = 0; 0 < getline(&buf, &cap, stdin);) {
+		if (buf[0] == '\n') {
+			i++;
+			continue;
+		}
+		for (char *ch = buf; *ch && *ch != '\n'; ++ch) {
+			groups[i] |= 1 << (*ch - 'a');
+		}
+	}
+	int sum = 0;
+	for (int i = 0; i < 512; ++i) {
+		sum += __builtin_popcount(groups[i]);
+	}
+	printf("%d\n", sum);
+}