summary refs log tree commit diff homepage
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
commit835da02e31dec8fc69481066120d4ae707eb65a9 (patch)
tree457d3b561015b3dbd23ac708033e34e349e7c032
parentSolve day 5 part 2 (diff)
downloadaoc-835da02e31dec8fc69481066120d4ae707eb65a9.tar.gz
aoc-835da02e31dec8fc69481066120d4ae707eb65a9.zip
Solve day 6 part 1
-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);
+}