From 83fa5d8bea6bf9759453698b745f248213434496 Mon Sep 17 00:00:00 2001 From: Mia Herkt Date: Sun, 4 Dec 2022 00:35:13 +0100 Subject: [PATCH] 03: Slightly smaller Python --- 03/solution.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/03/solution.py b/03/solution.py index 3999a13..8c91f8b 100755 --- a/03/solution.py +++ b/03/solution.py @@ -3,8 +3,8 @@ import sys S = G = 0 -for l in zip(*[iter(list(map(lambda c: c - ord('A') + 27 if c < ord('a') else c - ord('a') + 1, map(ord, x.strip()))) for x in sys.stdin)] * 3): +for l in zip(*[iter(list(map(lambda c: c - 38 if c < 97 else c - 96, map(ord, x.strip()))) for x in sys.stdin)] * 3): G += set.intersection(*map(set, l)).pop() - S += sum(set(x[:int(len(x) / 2)]).intersection(x[int(len(x) / 2):]).pop() for x in l) + S += sum(set(x[:len(x) // 2]).intersection(x[len(x) // 2:]).pop() for x in l) print(f"Silver: {S}\nGold: {G}")