andonyan

Faro Shuffle

Mar 8th, 2020
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. input_string = input().split()
  2. required_shuffles = int(input())
  3. first_half = []
  4. second_half = []
  5. output_string = []
  6. for i in range(1, len(input_string) // 2):
  7. first_half.append(input_string[i])
  8. second_half.append(input_string[i + ((len(input_string) - 2) // 2)])
  9. for n in range(required_shuffles):
  10. output_string = [item for t in list(zip(second_half, first_half)) for item in t]
  11. first_half.clear()
  12. second_half.clear()
  13. for m in range(len(output_string) // 2):
  14. first_half.append(output_string[m])
  15. second_half.append(output_string[m + (len(output_string) // 2)])
  16. output_string.insert(0, input_string[0])
  17. output_string.append(input_string[len(input_string) - 1])
  18. print(output_string)
Add Comment
Please, Sign In to add comment