Advertisement
Guest User

Weaponsmith

a guest
Feb 28th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. def is_valid(index, limit):
  2.     return 0 <= index < limit
  3.  
  4.  
  5. particles = input().split("|")
  6.  
  7. command = input()
  8.  
  9. while command != "Done":
  10.     action = command.split(" ")
  11.  
  12.     if "Left" in command:
  13.         if is_valid(int(action[2]), len(particles)):
  14.             if is_valid(int(action[2]) - 1, len(particles)):
  15.                 particles[int(action[2]) - 1], particles[int(action[2])] = \
  16.                      particles[int(action[2])], particles[int(action[2]) - 1]
  17.     elif "Right" in command:
  18.         if is_valid(int(action[2]), len(particles)):
  19.             if is_valid(int(action[2]) + 1, len(particles)):
  20.                 particles[int(action[2]) + 1], particles[int(action[2])] = \
  21.                     particles[int(action[2])], particles[int(action[2]) + 1]
  22.     elif "Even" in command:
  23.         print(' '.join([particle for particle in particles if particles.index(particle) % 2 == 0]))
  24.     elif "Odd" in command:
  25.         print(' '.join([particles[x] for x in range(len(particles)) if x % 2 != 0]))
  26.  
  27.     command = input()
  28.  
  29. print(f"You crafted {''.join(particles)}!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement