summary refs log tree commit diff homepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--2020/day06.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/2020/day06.c b/2020/day06.c
index 07c40a3..50124ae 100644
--- a/2020/day06.c
+++ b/2020/day06.c
@@ -3,19 +3,29 @@
 int main (void) {
 	size_t cap = 0;
 	char *buf = NULL;
-	unsigned groups[512] = {0};
+	unsigned groups1[512] = {0};
+	unsigned groups2[512] = {~0};
 	for (int i = 0; 0 < getline(&buf, &cap, stdin);) {
 		if (buf[0] == '\n') {
 			i++;
+			groups2[i] = ~0;
 			continue;
 		}
+		unsigned group2 = 0;
 		for (char *ch = buf; *ch && *ch != '\n'; ++ch) {
-			groups[i] |= 1 << (*ch - 'a');
+			groups1[i] |= 1 << (*ch - 'a');
+			group2 |= 1 << (*ch - 'a');
 		}
+		groups2[i] &= group2;
 	}
 	int sum = 0;
 	for (int i = 0; i < 512; ++i) {
-		sum += __builtin_popcount(groups[i]);
+		sum += __builtin_popcount(groups1[i]);
+	}
+	printf("%d\n", sum);
+	sum = 0;
+	for (int i = 0; i < 512; ++i) {
+		sum += __builtin_popcount(groups2[i]);
 	}
 	printf("%d\n", sum);
 }