Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main():
- with open('input5.txt') as file:
- stacks, commands= file.read().strip().split('\n\n')
- stacks= ["".join(list(row)).strip() for row in list(zip(*stacks.split("\n")[:-1][::]))[1::4] ]
- commands= [ [int(x) for x in line.split(" ")[1::2] ] for line in commands.split('\n') ]
- def rearrange(q, a, b, s):
- new_stacks= s[:]
- p= s[a-1][:q]
- new_stacks[a-1]= new_stacks[a-1][q:]
- new_stacks[b-1]= p[::-1] + new_stacks[b-1]
- #new_stacks[b-1]= p[::] + new_stacks[b-1] PART_TWO
- return new_stacks
- for move in commands:
- stacks= rearrange(*move, stacks)
- answer= ''
- for each in stacks:
- answer= answer+each[0]
- print(answer)
- return
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement