-1
Anyone who has spent any time around a deck of playing cards will recognize the riffle shuffle. The deck is cut in half and the two stacks are riffled simultaneously into the same pile before being tidied up in a sometimes visually appealing way.
This code-golf challenge is to write a function/method/(language equivalent) that performs the riffle shuffle on an array/stack/(language equivalent) of any size in the language of your choice.
As input, your function will except an array (language equivalent), plus how many times to run the shuffle. When done, it will return the shuffled array.
Your riffle shuffle function must implement the following algorithm:
Divide the
deckinto twostacksA
stackmust have a minimum of 40% of the totalcardsin thedeckand a maximum of 60%Choose a random
stackto start withDrop 1 - 7 cards from the bottom of the
starting stackto the top of the newly shuffleddeckDrop 1 - 7 cards from the bottom of the
other stackto the top of the newly shuffleddeckRepeat #3 and #4 until only one
stackremainsDrop the remaining
cardsfrom the remainingstackon top of the newly shuffleddeck
Smallest character count will be chosen as the answer in 1 week (May 29th).
This is the sample deck of cards to use:
[
'AH', '2H', '3H', '4H', '5H', '6H', '7H', '8H', '9H', '10H', 'JH', 'QH', 'KH',
'AC', '2C', '3C', '4C', '5C', '6C', '7C', '8C', '9C', '10C', 'JC', 'QC', 'KC',
'KD', 'QD', 'JD', '10D', '9D', '8D', '7D', '6D', '5D', '4D', '3D', '2D', 'AD',
'KS', 'QS', 'JS', '10S', '9S', '8S', '7S', '6S', '5S', '4S', '3S', '2S', 'AS'
]
Your answer should contain:
- Code-golfed code
- What the sample deck looks like after being shuffled twice
- Un-golfed code
3I've removed the extraneous [popularity-contest] here as it's not part of the scoring. Also, I've removed the langauge restrictions - we usually like to let everyone play instead of discouraging some from submitting an answer in a language they prefer. – Doorknob – 2014-05-22T19:48:11.517
3Two things: Firstly, you should explicitly specify that steps 1, 3 and 4 are subject to randomness (and possibly a uniform distribution, if you want to enforce that). Secondly, I don't think requesting the output of a random process helps much here, because it doesn't really prove the implementation is correct and will just clutter this post. – Martin Ender – 2014-05-22T19:58:26.723
Can I expect the deck to always have an even number of cards, or not? – Οurous – 2014-05-22T23:45:10.417
1This challenge would be interesting if it didn't give the step-by-step algorithm the code must implement. As is, the only competition is in how well you golf the operations (and what language you use). – xnor – 2014-05-23T03:14:11.330
@Ourous even or odd number of cards – user1886419 – 2014-05-23T13:45:44.033