From 225daece7f6724ac741e4b3856995b52f0c01535 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sun, 6 Dec 2020 00:27:01 -0500 Subject: Solve day 6 part 2 --- 2020/day06.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to '2020') 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); } -- cgit 1.4.1