diff options
author | June McEnroe <june@causal.agency> | 2020-12-06 00:27:01 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-12-06 01:22:09 -0500 |
commit | 225daece7f6724ac741e4b3856995b52f0c01535 (patch) | |
tree | 98d1bf68dd72c7ae9365082eeca35571e560cc49 /2020 | |
parent | Solve day 6 part 1 (diff) | |
download | aoc-225daece7f6724ac741e4b3856995b52f0c01535.tar.gz aoc-225daece7f6724ac741e4b3856995b52f0c01535.zip |
Solve day 6 part 2
Diffstat (limited to '2020')
-rw-r--r-- | 2020/day06.c | 16 |
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); } |