We call "perfect shuffle" the process of cutting a deck of cards into two equal halves, and then perfectly interleaving them: one card from the left stack, one card from the right stack, one card from the left stack, and so on.
Let "deck" be an array with an even number of elements. Write a function "perfect_shuffle(deck)" that returns a new array constructed according to this shuffle.
For example, perfect_shuffle([1, 2, 3, 4, 5, 6]) should return [1, 4, 2, 5, 3, 6].
Remark: For an array of 1024 elements, after 10 shuffles, we get back to the initial arrangement.
Solution Stats
Problem Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers17
Suggested Problems
-
Return the 3n+1 sequence for n
8483 Solvers
-
It dseon't mettar waht oedrr the lrettes in a wrod are.
2078 Solvers
-
Right Triangle Side Lengths (Inspired by Project Euler Problem 39)
2035 Solvers
-
117 Solvers
-
348 Solvers
More from this Author53
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!