summaryrefslogtreecommitdiffstats
path: root/20/py/d06.py
blob: 586463cc613efd72dd1ebaaed73d58939e319fe4 (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
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
import aoc20
import sys


def pt1(_in):
    res = 0
    questions = {s for s in "abcdefghijklmnopqrstuvwxyz"}
    for line in _in:
        if line == "\n":
            res += 26 - len(questions)
            questions = {s for s in "abcdefghijklmnopqrstuvwxyz"}
            continue
        for ans in line:
            if ans in questions:
                questions.remove(ans)
    res += 26 - len(questions)
    return res


def pt2(_in):
    res = 0
    questions = {s for s in "abcdefghijklmnopqrstuvwxyz"}
    for line in _in:
        person = set()
        if line == "\n":
            res += len(questions)
            questions = {s for s in "abcdefghijklmnopqrstuvwxyz"}
            continue
        for ans in line:
            person.add(ans)
        for q in questions.copy():
            if q not in person:
                questions.remove(q)
    res += len(questions)
    return res


if __name__ == "__main__":
    input = aoc20.read_input(sys.argv[1:], 6)
    print(pt1(input))
    print(pt2(input))