Card shuffles: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
Thundergnat (talk | contribs) m (Automated syntax highlighting fixup (second round - minor fixes)) |
||
Line 1: | Line 1: | ||
[[Category:Games]] |
[[Category:Games]] |
||
{{draft task|Games}}{{clarified-review}} |
{{draft task|Games}}{{clarified-review}} |
||
Line 39: | Line 38: | ||
* [[Poker hand_analyser]] |
* [[Poker hand_analyser]] |
||
* [[Go Fish]] |
* [[Go Fish]] |
||
=={{header|APL}}== |
=={{header|APL}}== |
||
If we generate a deck by |
If we generate a deck by |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="apl"> |
||
deck ← ⊂[1](52⍴'A23456789TJQK'),[0.5](13⍴'S'),(13⍴'H'),(13⍴'D'),(13⍴'C') |
deck ← ⊂[1](52⍴'A23456789TJQK'),[0.5](13⍴'S'),(13⍴'H'),(13⍴'D'),(13⍴'C') |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
Line 50: | Line 48: | ||
Then a generated deck looks like |
Then a generated deck looks like |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="apl"> |
||
AS 2S 3S 4S 5S 6S 7S 8S 9S TS JS QS KS AH 2H 3H 4H 5H 6H 7H 8H 9H TH JH QH KH AD 2D 3D 4D 5D 6D 7D 8D 9D TD JD QD KD AC 2C 3C 4C 5C 6C 7C 8C 9C TC JC QC KC |
AS 2S 3S 4S 5S 6S 7S 8S 9S TS JS QS KS AH 2H 3H 4H 5H 6H 7H 8H 9H TH JH QH KH AD 2D 3D 4D 5D 6D 7D 8D 9D TD JD QD KD AC 2C 3C 4C 5C 6C 7C 8C 9C TC JC QC KC |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
Line 56: | Line 54: | ||
Sorting a deck merely requires generating 52 unique random nunmbers from 1 to 52. |
Sorting a deck merely requires generating 52 unique random nunmbers from 1 to 52. |
||
<syntaxhighlight lang=text> |
<syntaxhighlight lang="text"> |
||
deck[52?52] |
deck[52?52] |
||
JD 8C TH 8D KH QH 6S AH 4D JS 5S AD 6H 3H 3D 5C 9C 7C 7S 4C JC 3S KD 9H 3C 4H 2D TD KS TS 7D JH 9D 8H 6D 7H 2H 4S QC AC KC 9S AS QS TC 2C 8S 5D 2S 6C 5H QD |
JD 8C TH 8D KH QH 6S AH 4D JS 5S AD 6H 3H 3D 5C 9C 7C 7S 4C JC 3S KD 9H 3C 4H 2D TD KS TS 7D JH 9D 8H 6D 7H 2H 4S QC AC KC 9S AS QS TC 2C 8S 5D 2S 6C 5H QD |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|C}}== |
=={{header|C}}== |
||
{{trans|Modula-2}} |
{{trans|Modula-2}} |
||
<syntaxhighlight lang=c>#include <stdio.h> |
<syntaxhighlight lang="c">#include <stdio.h> |
||
#include <stdlib.h> |
#include <stdlib.h> |
||
#include <string.h> |
#include <string.h> |
||
Line 251: | Line 248: | ||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] |
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] |
||
[20, 17, 18, 19, 14, 15, 16, 10, 11, 12, 13, 9, 8, 7, 5, 6, 1, 2, 3, 4]</pre> |
[20, 17, 18, 19, 14, 15, 16, 10, 11, 12, 13, 9, 8, 7, 5, 6, 1, 2, 3, 4]</pre> |
||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
{{trans|Java}} |
{{trans|Java}} |
||
<syntaxhighlight lang=csharp>using System; |
<syntaxhighlight lang="csharp">using System; |
||
using System.Collections.Generic; |
using System.Collections.Generic; |
||
using System.Linq; |
using System.Linq; |
||
Line 383: | Line 379: | ||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] |
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] |
||
[20, 17, 18, 19, 15, 16, 11, 12, 13, 14, 10, 7, 8, 9, 5, 6, 2, 3, 4, 1]</pre> |
[20, 17, 18, 19, 15, 16, 11, 12, 13, 14, 10, 7, 8, 9, 5, 6, 2, 3, 4, 1]</pre> |
||
=={{header|C++}}== |
=={{header|C++}}== |
||
<syntaxhighlight lang=cpp> |
<syntaxhighlight lang="cpp"> |
||
#include <time.h> |
#include <time.h> |
||
#include <algorithm> |
#include <algorithm> |
||
Line 529: | Line 524: | ||
14 4 17 3 12 5 19 6 20 2 16 11 8 15 7 13 10 18 9 1 |
14 4 17 3 12 5 19 6 20 2 16 11 8 15 7 13 10 18 9 1 |
||
</pre> |
</pre> |
||
=={{header|D}}== |
=={{header|D}}== |
||
{{trans|Java}} |
{{trans|Java}} |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="d">import std.container.array; |
||
import std.random; |
import std.random; |
||
import std.range; |
import std.range; |
||
Line 650: | Line 644: | ||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] |
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] |
||
[10, 17, 19, 13, 5, 12, 1, 2, 14, 4, 9, 16, 7, 3, 15, 20, 8, 11, 6, 18]</pre> |
[10, 17, 19, 13, 5, 12, 1, 2, 14, 4, 9, 16, 7, 3, 15, 20, 8, 11, 6, 18]</pre> |
||
=={{header|Go}}== |
=={{header|Go}}== |
||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
<syntaxhighlight lang=go>package main |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 767: | Line 760: | ||
[15 16 10 4 7 2 6 18 14 13 17 1 12 3 11 8 19 20 5 9] |
[15 16 10 4 7 2 6 18 14 13 17 1 12 3 11 8 19 20 5 9] |
||
</pre> |
</pre> |
||
=={{header|Groovy}}== |
=={{header|Groovy}}== |
||
{{trans|Java}} |
{{trans|Java}} |
||
<syntaxhighlight lang=groovy>class CardShuffles { |
<syntaxhighlight lang="groovy">class CardShuffles { |
||
private static final Random rand = new Random() |
private static final Random rand = new Random() |
||
Line 888: | Line 880: | ||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] |
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] |
||
[18, 17, 20, 5, 8, 11, 2, 4, 3, 7, 19, 10, 15, 14, 12, 13, 16, 9, 1, 6]</pre> |
[18, 17, 20, 5, 8, 11, 2, 4, 3, 7, 19, 10, 15, 14, 12, 13, 16, 9, 1, 6]</pre> |
||
=={{header|J}}== |
=={{header|J}}== |
||
{{eff note|J|({~ ?~@#)}} |
{{eff note|J|({~ ?~@#)}} |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="j">NB. overhand cut |
||
overhand=: (\: [: +/\ %@%:@# > # ?@# 0:)@]^:[ |
overhand=: (\: [: +/\ %@%:@# > # ?@# 0:)@]^:[ |
||
Line 904: | Line 895: | ||
Here are some examples of the underlying selection mechanism in action for a deck of 10 cards: |
Here are some examples of the underlying selection mechanism in action for a deck of 10 cards: |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="j"> ([: +/\ %@%:@# > # ?@# 0:) i.10 |
||
0 0 0 0 0 0 0 0 1 1 |
0 0 0 0 0 0 0 0 1 1 |
||
([: +/\ %@%:@# > # ?@# 0:) i.10 |
([: +/\ %@%:@# > # ?@# 0:) i.10 |
||
Line 919: | Line 910: | ||
Task examples: |
Task examples: |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="j"> 1 riffle i.20 |
||
0 1 2 3 4 5 6 7 8 13 14 9 15 16 17 10 18 11 12 19 |
0 1 2 3 4 5 6 7 8 13 14 9 15 16 17 10 18 11 12 19 |
||
10 riffle i.20 |
10 riffle i.20 |
||
Line 927: | Line 918: | ||
10 overhand i.20 |
10 overhand i.20 |
||
15 11 2 4 5 12 16 10 17 19 9 8 6 13 3 18 7 1 0 14</syntaxhighlight> |
15 11 2 4 5 12 16 10 17 19 9 8 6 13 3 18 7 1 0 14</syntaxhighlight> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
{{works with|Java|1.5+}} |
{{works with|Java|1.5+}} |
||
<syntaxhighlight lang=java5>import java.util.Arrays; |
<syntaxhighlight lang="java5">import java.util.Arrays; |
||
import java.util.Collections; |
import java.util.Collections; |
||
import java.util.LinkedList; |
import java.util.LinkedList; |
||
Line 1,052: | Line 1,042: | ||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] |
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] |
||
[18, 12, 13, 14, 2, 3, 15, 5, 9, 19, 7, 11, 1, 6, 4, 20, 16, 17, 10, 8]</pre> |
[18, 12, 13, 14, 2, 3, 15, 5, 9, 19, 7, 11, 1, 6, 4, 20, 16, 17, 10, 8]</pre> |
||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
{{works with|Julia|0.6}} |
{{works with|Julia|0.6}} |
||
<syntaxhighlight lang=julia>function riffleshuffle!(list::Vector, flips::Integer) |
<syntaxhighlight lang="julia">function riffleshuffle!(list::Vector, flips::Integer) |
||
len = length(list) |
len = length(list) |
||
# pre-allocate the left and right part for efficiency |
# pre-allocate the left and right part for efficiency |
||
Line 1,143: | Line 1,132: | ||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] |
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] |
||
-> [3, 11, 18, 14, 2, 12, 13, 4, 10, 19, 8, 16, 20, 5, 1, 6, 9, 15, 17, 7]</pre> |
-> [3, 11, 18, 14, 2, 12, 13, 4, 10, 19, 8, 16, 20, 5, 1, 6, 9, 15, 17, 7]</pre> |
||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
<syntaxhighlight lang=scala>// version 1.1.51 |
<syntaxhighlight lang="scala">// version 1.1.51 |
||
import java.util.Random |
import java.util.Random |
||
Line 1,227: | Line 1,215: | ||
[17, 9, 12, 15, 7, 13, 18, 8, 2, 20, 5, 10, 16, 6, 14, 4, 19, 3, 11, 1] |
[17, 9, 12, 15, 7, 13, 18, 8, 2, 20, 5, 10, 16, 6, 14, 4, 19, 3, 11, 1] |
||
</pre> |
</pre> |
||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
<syntaxhighlight lang=lua>-- Return a table respresenting a standard deck of cards in order |
<syntaxhighlight lang="lua">-- Return a table respresenting a standard deck of cards in order |
||
function newDeck () |
function newDeck () |
||
local cards, suits = {}, {"C", "D", "H", "S"} |
local cards, suits = {}, {"C", "D", "H", "S"} |
||
Line 1,303: | Line 1,290: | ||
5D 6D 7D 8D 9D TD JD QD KD AD QC KC AC 2D 3D 4C 5C 6C 7C 8C 9C TC JC 2C 3C |
5D 6D 7D 8D 9D TD JD QD KD AD QC KC AC 2D 3D 4C 5C 6C 7C 8C 9C TC JC 2C 3C |
||
</pre> |
</pre> |
||
=={{header|Modula-2}}== |
=={{header|Modula-2}}== |
||
<syntaxhighlight lang=modula2>MODULE CardShuffles; |
<syntaxhighlight lang="modula2">MODULE CardShuffles; |
||
FROM FormatString IMPORT FormatString; |
FROM FormatString IMPORT FormatString; |
||
FROM RandomNumbers IMPORT Random; |
FROM RandomNumbers IMPORT Random; |
||
Line 1,503: | Line 1,489: | ||
ReadChar; |
ReadChar; |
||
END CardShuffles.</syntaxhighlight> |
END CardShuffles.</syntaxhighlight> |
||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="nim">import algorithm, deques, random, sequtils, strutils |
||
proc riffle(deck: seq[int]; iterations: Positive): seq[int] = |
proc riffle(deck: seq[int]; iterations: Positive): seq[int] = |
||
Line 1,571: | Line 1,556: | ||
Standard library shuffle with one iteration: |
Standard library shuffle with one iteration: |
||
7 9 15 10 1 19 5 14 6 8 4 3 18 17 16 12 13 20 2 11</pre> |
7 9 15 10 1 19 5 14 6 8 4 3 18 17 16 12 13 20 2 11</pre> |
||
=={{header|PARI/GP}}== |
=={{header|PARI/GP}}== |
||
Riffle shuffle: |
Riffle shuffle: |
||
<syntaxhighlight lang=parigp>riffle(v)= |
<syntaxhighlight lang="parigp">riffle(v)= |
||
{ |
{ |
||
my(n=#v,k,t,deck=vector(n),left,right); |
my(n=#v,k,t,deck=vector(n),left,right); |
||
Line 1,594: | Line 1,578: | ||
Overhand shuffle: |
Overhand shuffle: |
||
<syntaxhighlight lang=parigp>overhand(v)= |
<syntaxhighlight lang="parigp">overhand(v)= |
||
{ |
{ |
||
my(u=[],t,n=2*#v\5); |
my(u=[],t,n=2*#v\5); |
||
Line 1,607: | Line 1,591: | ||
Usage: |
Usage: |
||
<syntaxhighlight lang=parigp>riffle([1..52]) |
<syntaxhighlight lang="parigp">riffle([1..52]) |
||
overhand([1..52])</syntaxhighlight> |
overhand([1..52])</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>%1 = [1, 2, 3, 21, 4, 22, 23, 5, 24, 25, 26, 6, 27, 28, 29, 30, 7, 31, 32, 33, 34, 35, 36, 8, 37, 38, 39, 40, 9, 10, 11, 12, 41, 42, 43, 13, 44, 45, 14, 46, 47, 48, 15, 16, 17, 49, 50, 18, 51, 19, 20, 52] |
<pre>%1 = [1, 2, 3, 21, 4, 22, 23, 5, 24, 25, 26, 6, 27, 28, 29, 30, 7, 31, 32, 33, 34, 35, 36, 8, 37, 38, 39, 40, 9, 10, 11, 12, 41, 42, 43, 13, 44, 45, 14, 46, 47, 48, 15, 16, 17, 49, 50, 18, 51, 19, 20, 52] |
||
%2 = [44, 45, 46, 47, 48, 49, 50, 51, 52, 43, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 23, 24, 25, 26, 27, 28, 29, 30, 31, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 1, 2, 3, 4]</pre> |
%2 = [44, 45, 46, 47, 48, 49, 50, 51, 52, 43, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 23, 24, 25, 26, 27, 28, 29, 30, 31, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 1, 2, 3, 4]</pre> |
||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
Follows the Raku implementation for the overhand shuffle, but uses classic one-liner for riffle. |
Follows the Raku implementation for the overhand shuffle, but uses classic one-liner for riffle. |
||
<syntaxhighlight lang=perl>sub overhand { |
<syntaxhighlight lang="perl">sub overhand { |
||
our @cards; local *cards = shift; |
our @cards; local *cards = shift; |
||
my(@splits,@shuffle); |
my(@splits,@shuffle); |
||
Line 1,643: | Line 1,626: | ||
<pre>9 11 5 2 4 14 1 3 8 6 15 13 16 12 19 20 7 18 10 17 |
<pre>9 11 5 2 4 14 1 3 8 6 15 13 16 12 19 20 7 18 10 17 |
||
1 10 19 9 18 8 17 7 16 6 15 5 14 4 13 3 12 2 11 20</pre> |
1 10 19 9 18 8 17 7 16 6 15 5 14 4 13 3 12 2 11 20</pre> |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<!--<syntaxhighlight lang= |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">function</span> <span style="color: #000000;">riffle</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> |
<span style="color: #008080;">function</span> <span style="color: #000000;">riffle</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span> |
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span> |
||
Line 1,697: | Line 1,679: | ||
KH TH AH QH 8D JC QC 8C JH 8H 9D KS TD AS KD 8S TC AD TS AC 9C KC 9H QD JD JS 9S QS |
KH TH AH QH 8D JC QC 8C JH 8H 9D KS TD AS KD 8S TC AD TS AC 9C KC 9H QD JD JS 9S QS |
||
</pre> |
</pre> |
||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="picolisp">(load "@lib/simul.l") |
||
(de riffle (Lst) |
(de riffle (Lst) |
||
Line 1,722: | Line 1,703: | ||
shuffle (5 3 13 15 17 12 14 11 2 1 19 7 6 9 18 8 10 4 16) |
shuffle (5 3 13 15 17 12 14 11 2 1 19 7 6 9 18 8 10 4 16) |
||
</pre> |
</pre> |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
{{trans|D}} |
{{trans|D}} |
||
<syntaxhighlight lang=python>import random |
<syntaxhighlight lang="python">import random |
||
def riffleShuffle(va, flips): |
def riffleShuffle(va, flips): |
||
Line 1,827: | Line 1,807: | ||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21] |
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21] |
||
[14, 12, 2, 17, 18, 21, 8, 4, 15, 9, 11, 10, 3, 1, 7, 19, 20, 6, 5, 16, 13]</pre> |
[14, 12, 2, 17, 18, 21, 8, 4, 15, 9, 11, 10, 3, 1, 7, 19, 20, 6, 5, 16, 13]</pre> |
||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
Line 1,836: | Line 1,815: | ||
Racket has a built in <code>shuffle</code> function. Frankly, I'd go with that in your own code! |
Racket has a built in <code>shuffle</code> function. Frankly, I'd go with that in your own code! |
||
<syntaxhighlight lang=racket>#lang typed/racket |
<syntaxhighlight lang="racket">#lang typed/racket |
||
;; --------------------------------------------------------------------------------------------------- |
;; --------------------------------------------------------------------------------------------------- |
||
;; Types and shuffle builder |
;; Types and shuffle builder |
||
Line 1,996: | Line 1,975: | ||
shuffle: (J♣ 2♠ 4♦ A♦ K♥ 6♦ 5♦ 8♣ 2♦ T♥ 4♠ 3♣ 7♦ 9♠ T♦ J... |
shuffle: (J♣ 2♠ 4♦ A♦ K♥ 6♦ 5♦ 8♣ 2♦ T♥ 4♠ 3♣ 7♦ 9♠ T♦ J... |
||
</pre> |
</pre> |
||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
(formerly Perl 6) |
(formerly Perl 6) |
||
<syntaxhighlight lang=raku line> |
<syntaxhighlight lang="raku" line> |
||
use v6; |
use v6; |
||
Line 2,027: | Line 2,005: | ||
say (^20).pick(*); |
say (^20).pick(*); |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
A little extra effort was put into the '''create''' subroutine to build any sort of deck, even a multiple deck as in canasta and samba (with/without jokers). Adding options for short decks, pinochle, schmear, six-handed '''500''', and the like would be prohibitive and muddy up the code and be distracting. |
A little extra effort was put into the '''create''' subroutine to build any sort of deck, even a multiple deck as in canasta and samba (with/without jokers). Adding options for short decks, pinochle, schmear, six-handed '''500''', and the like would be prohibitive and muddy up the code and be distracting. |
||
Six-handed 500 has additional cards of: <big> ♣11 ♣12 ♠11 ♠12 ♦11 ♦12 ♦13 ♦11 ♦12 ♦13 </big> |
Six-handed 500 has additional cards of: <big> ♣11 ♣12 ♠11 ♠12 ♦11 ♦12 ♦13 ♦11 ♦12 ♦13 </big> |
||
<syntaxhighlight lang=rexx>/*REXX program simulates various types of shuffling a deck of cards (any kind of deck).*/ |
<syntaxhighlight lang="rexx">/*REXX program simulates various types of shuffling a deck of cards (any kind of deck).*/ |
||
call create; call show 'new deck' /*build and display a new card deck. */ |
call create; call show 'new deck' /*build and display a new card deck. */ |
||
Line 2,101: | Line 2,078: | ||
♣A ♣2 ♣3 ♠2 ♥6 ♣6 ♣7 ♣8 ♦8 ♥8 ♣J ♣Q ♣K ♦A ♦2 ♦3 ♦4 ♥t ♦6 ♦7 ♠A ♦9 ♦t ♦J ♦Q ♠t ♥A ♥2 ♣t ♥4 ♠5 ♣5 ♦K ♥Q ♥9 ♦5 ♥J ♥3 ♥K ♣9 ♣4 ♠3 ♠4 ♠K ♠6 ♥7 ♠8 ♠9 ♠7 ♠J ♠Q ♥5 |
♣A ♣2 ♣3 ♠2 ♥6 ♣6 ♣7 ♣8 ♦8 ♥8 ♣J ♣Q ♣K ♦A ♦2 ♦3 ♦4 ♥t ♦6 ♦7 ♠A ♦9 ♦t ♦J ♦Q ♠t ♥A ♥2 ♣t ♥4 ♠5 ♣5 ♦K ♥Q ♥9 ♦5 ♥J ♥3 ♥K ♣9 ♣4 ♠3 ♠4 ♠K ♠6 ♥7 ♠8 ♠9 ♠7 ♠J ♠Q ♥5 |
||
</pre> |
</pre> |
||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
Two methods to solve the requirements, and a third one as bonus. |
Two methods to solve the requirements, and a third one as bonus. |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="ruby"> |
||
def riffle deck |
def riffle deck |
||
left, right = deck.partition{rand(10).odd?} |
left, right = deck.partition{rand(10).odd?} |
||
Line 2,137: | Line 2,113: | ||
p bonus(deck) |
p bonus(deck) |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
{{trans|Java}} |
{{trans|Java}} |
||
<syntaxhighlight lang=scala>import scala.collection.mutable.ListBuffer |
<syntaxhighlight lang="scala">import scala.collection.mutable.ListBuffer |
||
import scala.util.Random |
import scala.util.Random |
||
Line 2,259: | Line 2,234: | ||
List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20) |
List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20) |
||
List(1, 14, 12, 8, 15, 19, 4, 18, 11, 16, 13, 3, 2, 17, 10, 5, 9, 7, 6, 20)</pre> |
List(1, 14, 12, 8, 15, 19, 4, 18, 11, 16, 13, 3, 2, 17, 10, 5, 9, 7, 6, 20)</pre> |
||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="tcl"> |
||
proc riffle deck { |
proc riffle deck { |
||
set length [llength $deck] |
set length [llength $deck] |
||
Line 2,275: | Line 2,249: | ||
puts [overhand [list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52]] |
puts [overhand [list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52]] |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|Visual Basic .NET}}== |
=={{header|Visual Basic .NET}}== |
||
{{trans|C#}} |
{{trans|C#}} |
||
<syntaxhighlight lang=vbnet>Imports System.Runtime.CompilerServices |
<syntaxhighlight lang="vbnet">Imports System.Runtime.CompilerServices |
||
Imports System.Text |
Imports System.Text |
||
Line 2,407: | Line 2,380: | ||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] |
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] |
||
[19, 20, 15, 16, 17, 18, 13, 14, 10, 11, 12, 7, 8, 9, 4, 5, 6, 1, 2, 3]</pre> |
[19, 20, 15, 16, 17, 18, 13, 14, 10, 11, 12, 7, 8, 9, 4, 5, 6, 1, 2, 3]</pre> |
||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
<syntaxhighlight lang=ecmascript>import "random" for Random |
<syntaxhighlight lang="ecmascript">import "random" for Random |
||
var r = Random.new() |
var r = Random.new() |
||
Line 2,489: | Line 2,461: | ||
[9, 16, 2, 12, 8, 20, 13, 5, 4, 18, 17, 6, 11, 19, 1, 3, 14, 7, 10, 15] |
[9, 16, 2, 12, 8, 20, 13, 5, 4, 18, 17, 6, 11, 19, 1, 3, 14, 7, 10, 15] |
||
</pre> |
</pre> |
||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
A much better shuffle is List's shuffle method. |
A much better shuffle is List's shuffle method. |
||
<syntaxhighlight lang=zkl>fcn riffle(deck){ |
<syntaxhighlight lang="zkl">fcn riffle(deck){ |
||
len,N:=deck.len(),len/2; |
len,N:=deck.len(),len/2; |
||
newDeck:=N.pump(List,'wrap(n){ return(Void.Write,deck[n],deck[N+n]) }); |
newDeck:=N.pump(List,'wrap(n){ return(Void.Write,deck[n],deck[N+n]) }); |
||
Line 2,502: | Line 2,473: | ||
piles.pump(List,'wrap(n){ deck[n*N,N] }).reverse().flatten() |
piles.pump(List,'wrap(n){ deck[n*N,N] }).reverse().flatten() |
||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
<syntaxhighlight lang=zkl>riffle( [1..19].walk()).println(); |
<syntaxhighlight lang="zkl">riffle( [1..19].walk()).println(); |
||
overHand([1..19].walk()).println(); |
overHand([1..19].walk()).println(); |
||
[1..19].walk().shuffle().println();</syntaxhighlight> |
[1..19].walk().shuffle().println();</syntaxhighlight> |