diff options
Diffstat (limited to '')
-rw-r--r-- | 2020/day06.c | 21 |
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); +} |