blob: 4c25b52c765f555406ea2970a08e04fd1b0752c2 (
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
|
#!/usr/bin/python3
from itertools import zip_longest
def grouper(xs: list[str], n: int) -> list[list[str]]:
args = [iter(xs)] * n
return zip_longest(*args)
def process(group: list[str, str, str]) -> int:
x, y, z = group
c = set(x.strip()).intersection(y.strip()).intersection(z.strip()).pop()
return ord(c) - ord('a') + 1 if c >= 'a' else ord(c) - ord('A') + 27
def main() -> None:
with open("input", "r") as f:
print(sum(process(group) for group in grouper(f.readlines(), 3)))
if __name__ == "__main__":
main()
|