You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

30 lines
740 B

from copy import deepcopy
data = open("input.txt", 'r').read()
stacks, instructions = data.split("\n\n")
stacks = stacks.splitlines()
instructions = [i.split(" ") for i in instructions.splitlines()]
s = []
for i in range(int(stacks[-1][-2])):
s.append([])
for j in range(len(stacks)-1):
crate = stacks[-j-2][i*4+1]
if crate != " ":
s[i].append(crate)
s2 = deepcopy(s)
for i in instructions:
destination = int(i[5])-1
origin = int(i[3])-1
quantity = int(i[1])
s2[destination] += s2[origin][-quantity:]
for j in range(quantity):
s[destination].append(s[origin].pop())
s2[origin].pop()
print("".join([t.pop() for t in s]))
print("".join([t.pop() for t in s2]))