Advertisement
Guest User

Untitled

a guest
Dec 5th, 2022
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. def main():
  2.  
  3. with open('input5.txt') as file:
  4. stacks, commands= file.read().strip().split('\n\n')
  5. stacks= ["".join(list(row)).strip() for row in list(zip(*stacks.split("\n")[:-1][::]))[1::4] ]
  6. commands= [ [int(x) for x in line.split(" ")[1::2] ] for line in commands.split('\n') ]
  7.  
  8.  
  9. def rearrange(q, a, b, s):
  10. new_stacks= s[:]
  11. p= s[a-1][:q]
  12. new_stacks[a-1]= new_stacks[a-1][q:]
  13. new_stacks[b-1]= p[::-1] + new_stacks[b-1]
  14. #new_stacks[b-1]= p[::] + new_stacks[b-1] PART_TWO
  15. return new_stacks
  16.  
  17. for move in commands:
  18. stacks= rearrange(*move, stacks)
  19.  
  20. answer= ''
  21. for each in stacks:
  22. answer= answer+each[0]
  23.  
  24.  
  25. print(answer)
  26.  
  27.  
  28. return
  29.  
  30.  
  31.  
  32. if __name__ == '__main__':
  33. main()
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement