shorten a tad

This commit is contained in:
DUEFON 2022-12-05 20:30:08 +01:00 committed by Eivind Øksnevad
parent e0b63fb15a
commit 621653a442
1 changed files with 3 additions and 8 deletions

View File

@ -2,20 +2,15 @@
from useful import * from useful import *
def stuff(l): def stuff(l):
d = {x: True for x in l[:len(l)//2]} return next(iter(set(l[:len(l)//2]) & set(l[len(l)//2:])))
return next(x for x in l[len(l)//2:] if d.get(x))
def points(c): def points(c):
o = ord(c) o = ord(c)
return 27 + o - ord('A') if o < ord('a') else 1 + o - ord('a') return 27 + o - ord('A') if o < ord('a') else 1 + o - ord('a')
def twuff(trip): def twuff(trip):
d = [{x: True for x in l} for l in trip[:2]] return next(iter(reduce(lambda a, b: a & b, (set(l) for l in trip))))
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)) ls = lines(open(0))
print(sum(points(stuff(l)) for l in ls)) print(sum(points(stuff(l)) for l in ls))
print(sum(points(twuff(l)) for l in trips(ls))) print(sum(points(twuff(l)) for l in batched(ls, 3)))