Card shuffles: Difference between revisions

m
Line 166:
{{eff note|J|({~ ?~@#)}}
 
<lang J>NB. overhand cut rotates the deck to an arbitrary position
overhand=: (\: [: +/\ %@%:@# > # ?@# 0:)@]^:[
 
Line 173:
 
Overhand shuffle is implemented not as was described in wikipedia but as described on the talk page "the cuts are taken from the top of the deck and placed on top of the new deck". The probability of a cut occurring between each pair of cards in this overhand shuffle is proportional to the reciprocal of the square root of the number of cards in the deck.
 
In other words, overhand cut breaks the deck into some number of pieces and reverses the order of those pieces.
 
Here are some examples of the underlying selection mechanism in action for a deck of 10 cards:
 
<lang J> ([: +/\ %@%:@# > # ?@# 0:) i.10
0 0 0 0 0 0 0 0 1 1
([: +/\ %@%:@# > # ?@# 0:) i.10
1 1 2 2 2 3 3 3 3 3
([: +/\ %@%:@# > # ?@# 0:) i.10
0 1 1 2 3 3 3 3 4 5
([: +/\ %@%:@# > # ?@# 0:) i.10
0 1 1 1 1 2 2 3 3 3</lang>
 
The final step of a cut is to sort the deck in descending order based on the numbers we compute this way.
 
The left argument says how many of these cuts to perform.
 
Task examples:
6,962

edits