package main
import "core:os"
import "core:fmt"
import "core:strings"
import "core:strconv"
import "core:container"
// `{ 'a'..'z' }` didn't work :(
All : bit_set['a'..'z'] : {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
None : bit_set['a'..'z'] : {};
Person :: struct {
answers: bit_set['a'..'z']
}
Group :: struct {
answers: bit_set['a'..'z']
people: [dynamic]Person,
answer_count: int,
all_answer_count: int,
}
main :: proc() {
input, err := os.read_entire_file("input.txt");
inputStr := string(input);
lines := strings.split(inputStr, "\n");
groups := make([dynamic]Group, 0);
currentGroup := Group { {}, make([dynamic]Person, 0), 0, 0 };
totalAnswerCount := 0;
totalAllAnswerCount := 0;
for line in lines {
line := strings.trim_space(line);
if line == "" {
// Append current group
append(&groups, currentGroup);
totalAnswerCount += currentGroup.answer_count;
answers := All;
if len(currentGroup.people) <= 0 do answers = None;
for person in currentGroup.people {
for c in 'a'..'z' {
if c not_in person.answers do answers &~= { c };
}
}
all_count := 0;
for c in 'a'..'z' {
if c in answers do all_count += 1;
}
totalAllAnswerCount += all_count;
// New group
currentGroup = Group { {}, make([dynamic]Person, 0), 0, all_count };
} else {
person := Person {};
for c in line {
if c not_in currentGroup.answers {
currentGroup.answer_count += 1;
}
currentGroup.answers |= { c };
person.answers |= { c };
}
append(¤tGroup.people, person);
}
}
fmt.println(totalAnswerCount, totalAllAnswerCount);
}