SimeonTs

SUPyF2 Lists Basics Exercise - 05. Faro Shuffle

Oct 3rd, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. """
  2. Lists Basics - Exercise
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1725#4
  4.  
  5. SUPyF2 Lists Basics Exercise - 05. Faro Shuffle
  6.  
  7. Problem:
  8. A faro shuffle of a deck of playing cards is a shuffle in which the deck is split exactly in half and then the cards in
  9. the two halves are perfectly interwoven, such that the original bottom card is still on the bottom and the original
  10. top card is still on top.
  11. For example, faro shuffling the list
  12. ['ace', 'two', 'three', 'four', 'five', 'six'] once, gives ['ace', 'four', 'two', 'five', 'three', 'six' ]
  13. Write a program that receives a single string (cards separated by a space) and on the second line receives a number
  14. of faro shuffles that have to be made. Print the state of the deck after the shuffle
  15. Note: The length of the deck of cards will always be an even number
  16.  
  17. Example:
  18. Input:                      Output:
  19. a b c d e f g h
  20. 5
  21.                            ['a', 'c', 'e', 'g', 'b', 'd', 'f', 'h']
  22. one two three four
  23. 3                           ['one', 'three', 'two', 'four']
  24. """
  25.  
  26. cards = [card for card in input().split(" ")]
  27. times_to_split = int(input())
  28.  
  29. for each_time in range(times_to_split):
  30.     shuffled_list = []
  31.     for (a, b) in zip(cards[:len(cards)//2], cards[len(cards)//2:]):
  32.         shuffled_list.append(a)
  33.         shuffled_list.append(b)
  34.     cards = shuffled_list
  35.  
  36. print(cards)
Add Comment
Please, Sign In to add comment