summary refs log tree commit diff homepage
path: root/2020/day06.c
blob: 50124aed16460da9137dc4c8b449e05d143ce1af (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include <stdlib.h>
int main (void) {
	size_t cap = 0;
	char *buf = NULL;
	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) {
			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(groups1[i]);
	}
	printf("%d\n", sum);
	sum = 0;
	for (int i = 0; i < 512; ++i) {
		sum += __builtin_popcount(groups2[i]);
	}
	printf("%d\n", sum);
}
rd EmperorJune McEnroe 2022-06-25Bump xterm font size to 12June McEnroe 2022-06-10Handle subshells (and functions) inside substitutionsJune McEnroe 2022-06-10Switch to jorts Install scriptJune McEnroe 2022-06-08Indicate if still reading or no resultsJune McEnroe 2022-06-08Add Maiden, Mother, CroneJune McEnroe 2022-06-05FIRST SHOW IN 2.5 YEARS BABEY!!!June McEnroe 2022-06-03Set line number on File linesJune McEnroe 2022-06-03Stop polling stdin after EOFJune McEnroe 2022-06-02Set TABSIZE=4June McEnroe 2022-06-02Do basic match highlightingJune McEnroe 2022-06-02Clean up parsing a littleJune McEnroe 2022-06-02Don't duplicate path stringJune McEnroe 2022-06-02Use stderr instead of /dev/tty, realloc buffer if lines too longJune McEnroe 2022-06-02Add initial working version of qfJune McEnroe 2022-05-29Set prompt for okshJune McEnroe