From 3be62b50f80c1d67d9867775242c33e88266fec8 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 3 Dec 2022 06:29:07 +0100 Subject: Add 2022 day 3 solutions --- 2022/03/puzzle-2.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 2022/03/puzzle-2.py (limited to '2022/03/puzzle-2.py') diff --git a/2022/03/puzzle-2.py b/2022/03/puzzle-2.py new file mode 100755 index 0000000..7be3e84 --- /dev/null +++ b/2022/03/puzzle-2.py @@ -0,0 +1,31 @@ +#!/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 main() -> None: + with open("input", "r") as f: + data = f.readlines() + + acc = 0 + data = grouper(data, 3) + + for group in data: + for c in group[0]: + if group[1].find(c) != -1 and group[2].find(c) != -1: + if 'a' <= c <= 'z': + acc += ord(c) - ord('a') + 1 + else: + acc += ord(c) - ord('A') + 27 + break + + print(acc) + + +if __name__ == "__main__": + main() -- cgit v1.2.3