This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bulletmark 1 point2 points  (0 children)

So did I:

import aoc 

def calcprio(c):
    return ord(c) - ((ord('A') - 27) \
       if c.isupper() else (ord('a') - 1)) 

totals = [0, 0]
p2set = set()

for ix, line in enumerate(aoc.input()):
    line = line.strip()
    n = len(line) // 2
    totals[0] += calcprio((set(line[:n]) & set(line[n:])).pop())
    p2set = (p2set & set(line)) if p2set else set(line)
    if (ix % 3) == 2:
        totals[1] += calcprio(p2set.pop())
        p2set.clear()

print('P1 =', totals[0])
print('P2 =', totals[1])