summary refs log tree commit diff homepage
path: root/2020/day06.c
blob: 07c40a377af8ee3448d7d4b1e9bc0f29bc4d42ed (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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);
}