Perfect deck shuffle

Created by Julien Palard

Simulate a perfect suffle of a deck of cards.

A perfect shuffle of a deck of card is splitting a deck of cards into equal halves, and perfectly interleaving them.

Perfectly shuffling [1, 2, 3, 4, 5, 6] gives [1, 4, 2, 5, 3, 6].

(We consider that a deck of cards has an even number of cards.)

You'll expose a perfect_shuffle(deck) function, perfectly shuffling the given iterable.

Did you know that if you shuffle 10 times a deck of 1024 cards, the deck returns to its initial state ? It's probably a good way to test your implementation.

There's no corrections yet, hit the `Submit` button to send your code to the correction bot.

Keyboard shortcuts:

  • Ctrl-Enter: Send your code to the correction bot.
  • Escape: Get back to the instructions tab.

See solutions