advent2022/three.py

17 lines
427 B
Python
Executable File

#!/usr/bin/env python3
from useful import *
def stuff(l):
return next(iter(set(l[:len(l)//2]) & set(l[len(l)//2:])))
def points(c):
o = ord(c)
return 27 + o - ord('A') if o < ord('a') else 1 + o - ord('a')
def twuff(trip):
return next(iter(reduce(lambda a, b: a & b, (set(l) for l in trip))))
ls = lines(open(0))
print(sum(points(stuff(l)) for l in ls))
print(sum(points(twuff(l)) for l in batched(ls, 3)))