aboutsummaryrefslogtreecommitdiff
path: root/2022
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2022-12-03 06:47:51 +0100
committerThomas Voss <mail@thomasvoss.com> 2022-12-03 06:47:51 +0100
commitccc1ac4b643dfa692fe0c37f57e9493494245ecb (patch)
treec0e20cabcd3dc844732fe7f7cc678997406659e0 /2022
parent50f590b6a4e5ac58b8e6baa655889097daef996d (diff)
Same as last commit
Diffstat (limited to '2022')
-rwxr-xr-x2022/03/puzzle-2.py22
1 files changed, 7 insertions, 15 deletions
diff --git a/2022/03/puzzle-2.py b/2022/03/puzzle-2.py
index 7be3e84..4c25b52 100755
--- a/2022/03/puzzle-2.py
+++ b/2022/03/puzzle-2.py
@@ -8,23 +8,15 @@ def grouper(xs: list[str], n: int) -> list[list[str]]:
return zip_longest(*args)
-def main() -> None:
- with open("input", "r") as f:
- data = f.readlines()
-
- acc = 0
- data = grouper(data, 3)
+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
- 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)
+def main() -> None:
+ with open("input", "r") as f:
+ print(sum(process(group) for group in grouper(f.readlines(), 3)))
if __name__ == "__main__":