AoC2022/03_02.c

39 lines
637 B
C
Raw Normal View History

2022-12-03 14:54:25 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int get_prio (char c) {
int r = (int) (c - 'a'+1);
if (r > 0) return r;
return r + 'A' - 7;
}
int main () {
char cur[50];
int half = 0;
u_int64_t masks[3] = {0};
int sum = 0;
int j =0;
while (fgets(cur,50,stdin) != NULL) {
int i;
for (i=0; i<strlen(cur)-1; i++) {
masks[j] |= (1LL << get_prio(cur[i]));
}
if (j == 2) {
u_int64_t mask = 0;
mask = masks[0] & masks[1] & masks[2];
for (int k=0; k<3; k++) masks[k] = 0;
int k =-1;
while (mask > 0) {
k++;
mask >>=1LL;
}
sum += k;
j = -1;
}
j++;
}
printf("%d\n", sum);
}