aboutsummaryrefslogtreecommitdiff
path: root/2022/03/puzzle-1.py
blob: d0a788d2247bfc9e02b8dabb99c2ee9848dc59f1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/python3

def cut(s: str) -> (str, str):
	n = len(s) // 2
	return s[:n], s[n:]


def process(line: str) -> int:
	car, cdr = cut(line)
	c = set(car).intersection(cdr).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(line) for line in f.readlines()))


if __name__ == "__main__":
	main()