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.
45 lines
1.0 KiB
45 lines
1.0 KiB
lines = open("input.txt", "r").read().splitlines()
|
|
|
|
|
|
def get_instr_state(lines):
|
|
state = []
|
|
instr = []
|
|
flag = False
|
|
for line in lines:
|
|
if line == "":
|
|
flag = True
|
|
continue
|
|
if not flag:
|
|
state.append(line)
|
|
else:
|
|
instr.append(line)
|
|
return state, instr
|
|
|
|
|
|
def parse_state(state):
|
|
new_state = []
|
|
for old_line in state:
|
|
new_line = []
|
|
for i in range(1, len(old_line), 4):
|
|
new_line.append(old_line[i])
|
|
new_state.append(new_line)
|
|
new_state = list(map(list, zip(*new_state)))
|
|
final_state = []
|
|
for line in new_state:
|
|
final_state.append([x for x in line if x != " "])
|
|
return final_state
|
|
|
|
|
|
raw_state, instr = get_instr_state(lines)
|
|
state = parse_state(raw_state)
|
|
|
|
for i in instr:
|
|
i = i.split(" ")
|
|
x, y, z = int(i[1]), int(i[3]), int(i[5])
|
|
for j in range(x):
|
|
elem = state[y - 1].pop(0)
|
|
state[z - 1].insert(0, elem)
|
|
|
|
for s in state:
|
|
print(s[0], end="")
|