summaryrefslogtreecommitdiffstats
path: root/20/py/d06.py
blob: 8604b0068c22d2ca6d74a584ec0b8a4cabd440ea (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
43
44
#!/usr/bin/env python3
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__":
    if len(sys.argv) > 1:
        input = open(sys.argv[1], "r").readlines()
    else:
        input = open("../input/06", "r").readlines()
    print(pt1(input))
    print(pt2(input))