From e0b63fb15ab49d4b92e0f1306dbbad09b31e8f64 Mon Sep 17 00:00:00 2001 From: DUEFON Date: Mon, 5 Dec 2022 20:22:31 +0100 Subject: [PATCH] 3 2 --- three.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/three.py b/three.py index 39f77f9..0eeee0a 100755 --- a/three.py +++ b/three.py @@ -9,5 +9,13 @@ def points(c): o = ord(c) return 27 + o - ord('A') if o < ord('a') else 1 + o - ord('a') -#ic([points(stuff(l)) for l in lines(open(0))]) -print(sum(points(stuff(l)) for l in lines(open(0)))) +def twuff(trip): + d = [{x: True for x in l} for l in trip[:2]] + return next(c for c in trip[2] if c in d[0] and c in d[1]) + +def trips(ls): + return [[ls[i], ls[i+1], ls[i+2]] for i in range(0, len(ls), 3)] + +ls = lines(open(0)) +print(sum(points(stuff(l)) for l in ls)) +print(sum(points(twuff(l)) for l in trips(ls)))