Skip to content
advent of code 2020

day 06

custom customs

approach

each group is parsed into a Counter of answered letters along with the number of people in it. part 1 sums, over all groups, how many distinct letters appear, which is just the size of the counter.

part 2 wants the letters everyone in the group answered. since the counter knows how many people picked each letter, those are the letters whose count equals the group size.

the trick

keep counts, not sets: "anyone" is the number of keys and "everyone" is the keys whose count equals the group size.

python
def part2(l = groups):
    res = 0
    for gc, gs in l:
        res += len([o for o in gc if gc[o] == gs])
    return res