aoc2022/05/2022-12-05-B.py

25 lines
545 B
Python
Raw Normal View History

2022-12-05 10:17:37 +00:00
#!/usr/bin/env python3
import numpy as np
import re
piles = []
a = open("05/i").read().split("\n\n")
b = list(reversed(a[0].split("\n")))
for l in b:
temp = []
for i in range(0,len(l),4):
temp.append(l[i+1].strip())
piles.append(temp)
piles=[[i for i in x if i] for x in np.transpose(piles)]
for l in a[1].strip().split("\n"):
c=list(map(int,re.search("move (\d+) from (\d+) to (\d+)",l).groups()))
piles[c[2]-1].extend(piles[c[1]-1][-c[0]:])
del piles[c[1]-1][-c[0]:]
d = [i.pop() for i in piles]
print(d)