summaryrefslogtreecommitdiff
path: root/3_2022.py
blob: 1734756c7ad62db8d1f0a57fd890de769a302bc1 (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
25
26
27
28
def score(c):
    if "a" <= c <= "z":
        return ord(c) - ord("a") + 1
    else:
        return ord(c) - ord("A") + 27


p1 = 0
for line in open("3_2022.txt"):
    x = line.strip()
    assert len(x) % 2 == 0
    y, z = x[: len(x) // 2], x[len(x) // 2 :]
    for c in y:
        if c in z:
            p1 += score(c)
            break
print(p1)

p2 = 0
i = [line for line in open("3_2022.txt")]
j = 0
while j < len(i):
    for c in i[j]:
        if c in i[j + 1] and c in i[j + 2]:
            p2 += score(c)
            break
    j += 3
print(p2)