Advertisement
Guest User

Untitled

a guest
Sep 7th, 2020
832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. sequence = input().split()
  2. command = input()
  3. count_moves = 1
  4.  
  5. while command != 'end':
  6. tokens = command.split()
  7. idx_one = int(tokens[0])
  8. idx_two = int(tokens[1])
  9. if idx_one != idx_two and 0 <= idx_one < len(sequence) and 0 <= idx_two < len(sequence):
  10. if sequence[idx_one] == sequence[idx_two]:
  11. print(f"Congrats! You have found matching elements - {sequence[idx_one]}!")
  12. indices = {idx_one, idx_two}
  13. sequence = [v for i, v in enumerate(sequence) if i not in indices]
  14. else:
  15. print(f"Try again!")
  16. else:
  17. print(f"Invalid input! Adding additional elements to the board")
  18. mid_point = len(sequence) // 2
  19. if idx_one < 0 or idx_two < 0:
  20. sequence = sequence[0:mid_point] + [('-' + str(count_moves) + 'a')] + [('-' + str(count_moves) + 'a')] + sequence[mid_point:]
  21. else:
  22. sequence = sequence[0:mid_point] + [(str(count_moves) + 'a') * 2] + [(str(count_moves) + 'a') * 2] + sequence[mid_point:]
  23.  
  24. if len(sequence) == 0:
  25. break
  26.  
  27. count_moves += 1
  28. command = input()
  29. if len(sequence) > 0:
  30. print(f'Sorry you lose :(')
  31. print(' '.join(sequence))
  32. else:
  33. print(f"You have won in {count_moves} turns!")
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement