summaryrefslogtreecommitdiff
path: root/day6/day6.py
blob: 7bad5d2ce2a19c79ebdbedaaa2abb105ad4fc268 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""Day 6."""
from collections import Counter


def score_part1(group):
    """Determine score for group in part 1."""
    return len(set(group.replace("\n", "")))


def score_part2(group):
    """Determine score for group in part 2."""
    group_size = group.count("\n") + 1
    counter = Counter(group.replace("\n", ""))
    return sum(1 for _, occurences in counter.items() if occurences == group_size)


with open("input") as f:
    groups = f.read().rstrip().split("\n\n")

# Part 1
print(sum(map(score_part1, groups)))

# Part 2
print(sum(map(score_part2, groups)))