diff options
author | June McEnroe <june@causal.agency> | 2020-12-06 00:15:38 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-12-06 00:15:38 -0500 |
commit | 835da02e31dec8fc69481066120d4ae707eb65a9 (patch) | |
tree | 457d3b561015b3dbd23ac708033e34e349e7c032 | |
parent | Solve day 5 part 2 (diff) | |
download | aoc-835da02e31dec8fc69481066120d4ae707eb65a9.tar.gz aoc-835da02e31dec8fc69481066120d4ae707eb65a9.zip |
Solve day 6 part 1
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); +} |