summary refs log tree commit diff homepage
diff options
context:
space:
mode:
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);
+}
tall.sh?id=86702e39cb0af987b4d60c197460666cab260469&follow=1'>Add OpenBSD to install.shJune McEnroe Straightforward. 2020-06-03Add The Song of AchillesJune McEnroe 2020-06-01Allow redirecting input in everJune McEnroe 2020-05-31Add %c conversion to c scriptJune McEnroe 2020-05-31Add c script to READMEJune McEnroe 2020-05-31Add c scriptJune McEnroe 2020-05-31Update mdoc source URLsJune McEnroe 2020-05-26Remove unfinished PSF fontsJune McEnroe