part 2 for 5 and 2

This commit is contained in:
DUEFON 2022-12-05 19:31:03 +01:00 committed by Eivind Øksnevad
parent c40cc64a22
commit dee7f57b2a
2 changed files with 10 additions and 5 deletions

View File

@ -5,12 +5,12 @@ beg, rec = headerfooter(open(0))
begl = beg.split('\n')
a = np.asarray([c for l in begl for c in l]).reshape((len(begl), -1)).T[1::4,::-1]
dock = [None, *[deque(c for c in l if not c in '0123456789 ') for l in a]]
ic(a, dock)
twock = [None, *[deque(c for c in l if not c in '0123456789 ') for l in a]]
for l in rec.strip().split('\n'):
num, src, dst = (int(n) for n in re.match(r'move (\d+) from (\d+) to (\d+)', l).groups())
ic(num, src, dst)
for i in range(num): # ugh
dock[dst].extend(dock[src].pop())
dock[dst].extend(dock[src].pop() for i in range(num)) # ugh
twock[dst].extend([twock[src].pop() for i in range(num)][::-1])
print(''.join([d.pop() for d in dock[1:]]))
print(''.join([d.pop() for d in twock[1:]]))

7
two.py
View File

@ -12,6 +12,11 @@ def bonus(a, b): # for b (that's us)
[0, 3, 6],
[6, 0, 3]][prd(a)][prd(b)]
def wpn(a, b): # for b (that's us)
return 'XYZ'[[[2, 0, 1],
[0, 1, 2],
[1, 2, 0]][prd(a)][prd(b)]]
rounds = [[l[0], l[2]] for l in lines(open(0))]
ic([[a, b, scores(b), bonus(a, b)] for a, b in rounds])
print(sum(scores(b) + bonus(a, b) for a, b in rounds))
print(sum(scores(wpn(a, b)) + bonus(a, wpn(a, b)) for a, b in rounds))