advent2022/two.py

23 lines
557 B
Python
Raw Permalink Normal View History

2022-12-05 20:24:48 +02:00
#!/usr/bin/env python3
from useful import *
def prd(c):
return (ord(c) - ord('A')) % 23
def scores(c):
return 1 + prd(c)
def bonus(a, b): # for b (that's us)
return [[3, 6, 0],
[0, 3, 6],
[6, 0, 3]][prd(a)][prd(b)]
2022-12-05 20:31:03 +02:00
def wpn(a, b): # for b (that's us)
return 'XYZ'[[[2, 0, 1],
[0, 1, 2],
[1, 2, 0]][prd(a)][prd(b)]]
2022-12-05 20:24:48 +02:00
rounds = [[l[0], l[2]] for l in lines(open(0))]
print(sum(scores(b) + bonus(a, b) for a, b in rounds))
2022-12-05 20:31:03 +02:00
print(sum(scores(wpn(a, b)) + bonus(a, wpn(a, b)) for a, b in rounds))