Mind boggling card trick: Difference between revisions
Content deleted Content added
→{{header|Lua}}: added Lua solution |
Thundergnat (talk | contribs) m syntax highlighting fixup automation |
||
Line 36: | Line 36: | ||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="11l">//import random |
||
V n = 52 |
V n = 52 |
||
V Black = ‘Black’ |
V Black = ‘Black’ |
||
Line 73: | Line 73: | ||
print(‘Yeha! The mathematicians assertion is correct.’) |
print(‘Yeha! The mathematicians assertion is correct.’) |
||
E |
E |
||
print(‘Whoops - The mathematicians (or my card manipulations) are flakey’)</ |
print(‘Whoops - The mathematicians (or my card manipulations) are flakey’)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 84: | Line 84: | ||
=={{header|AppleScript}}== |
=={{header|AppleScript}}== |
||
< |
<syntaxhighlight lang="applescript">use AppleScript version "2.5" -- OS X 10.11 (El Capitan) or later |
||
use framework "Foundation" |
use framework "Foundation" |
||
use framework "GameplayKit" -- For randomising functions. |
use framework "GameplayKit" -- For randomising functions. |
||
Line 175: | Line 175: | ||
return text 1 thru -2 of join(output, linefeed) |
return text 1 thru -2 of join(output, linefeed) |
||
end task |
end task |
||
return task()</ |
return task()</syntaxhighlight> |
||
{{output}} |
{{output}} |
||
< |
<syntaxhighlight lang="applescript">"Test 1: Assertion is true |
||
Red pile: 3♦️, 2♦️, 9♣️, 6♣️, 3♥️, 9♥️, A♠️, 3♠️, 2♥️, Q♠️, 7♥️, K♥️ |
Red pile: 3♦️, 2♦️, 9♣️, 6♣️, 3♥️, 9♥️, A♠️, 3♠️, 2♥️, Q♠️, 7♥️, K♥️ |
||
Black pile: Q♥️, J♣️, 7♦️, 4♦️, 8♦️, 5♥️, K♣️, 10♠️, 10♣️, 7♣️, 2♣️, 9♦️, 5♣️, 6♦️ |
Black pile: Q♥️, J♣️, 7♦️, 4♦️, 8♦️, 5♥️, K♣️, 10♠️, 10♣️, 7♣️, 2♣️, 9♦️, 5♣️, 6♦️ |
||
Line 206: | Line 206: | ||
Black pile: 2♦️, 2♥️, 8♣️, 9♣️, 7♥️, 3♣️, Q♠️, 10♠️, 8♥️, 10♣️, K♣️, 5♠️, 4♦️, 3♥️, 6♥️ |
Black pile: 2♦️, 2♥️, 8♣️, 9♣️, 7♥️, 3♣️, Q♠️, 10♠️, 8♥️, 10♣️, K♣️, 5♠️, 4♦️, 3♥️, 6♥️ |
||
Discards: 7♦️, J♥️, 7♣️, 4♠️, 6♦️, 4♣️, 7♠️, Q♥️, J♠️, Q♦️, 6♠️, J♣️, A♥️ |
Discards: 7♦️, J♥️, 7♣️, 4♠️, 6♦️, 4♣️, 7♠️, Q♥️, J♠️, Q♦️, 6♠️, J♣️, A♥️ |
||
9♦️, K♦️, J♦️, 3♠️, 5♣️, Q♣️, A♣️, K♠️, 8♠️, 9♥️, A♠️, 6♣️, A♦️"</ |
9♦️, K♦️, J♦️, 3♠️, 5♣️, Q♣️, A♣️, K♠️, 8♠️, 9♥️, A♠️, 6♣️, A♦️"</syntaxhighlight> |
||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
< |
<syntaxhighlight lang="autohotkey">;========================================================== |
||
; create cards |
; create cards |
||
cards := [], suits := ["♠","♥","♦","♣"], num := 0 |
cards := [], suits := ["♠","♥","♦","♣"], num := 0 |
||
Line 334: | Line 334: | ||
SB_SetText(countB " Face Down Black Cards", 2) |
SB_SetText(countB " Face Down Black Cards", 2) |
||
return |
return |
||
;==========================================================</ |
;==========================================================</syntaxhighlight> |
||
=={{header|C}}== |
=={{header|C}}== |
||
< |
<syntaxhighlight lang="c">#include <stdio.h> |
||
#include <stdlib.h> |
#include <stdlib.h> |
||
#include <stdint.h> |
#include <stdint.h> |
||
Line 467: | Line 467: | ||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 495: | Line 495: | ||
=={{header|Crystal}}== |
=={{header|Crystal}}== |
||
{{trans|Ruby}} |
{{trans|Ruby}} |
||
< |
<syntaxhighlight lang="ruby">deck = ([:black, :red] * 26 ).shuffle |
||
black_pile, red_pile, discard = [] of Symbol, [] of Symbol, [] of Symbol |
black_pile, red_pile, discard = [] of Symbol, [] of Symbol, [] of Symbol |
||
Line 513: | Line 513: | ||
puts "The magician predicts there will be #{black_pile.count( :black )} red cards in the other pile. |
puts "The magician predicts there will be #{black_pile.count( :black )} red cards in the other pile. |
||
Drumroll... |
Drumroll... |
||
There were #{red_pile.count( :red )}!"</ |
There were #{red_pile.count( :red )}!"</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>The magician predicts there will be 7 red cards in the other pile. |
<pre>The magician predicts there will be 7 red cards in the other pile. |
||
Line 521: | Line 521: | ||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
< |
<syntaxhighlight lang="fsharp"> |
||
//Be boggled? Nigel Galloway: September 19th., 2018 |
//Be boggled? Nigel Galloway: September 19th., 2018 |
||
let N=System.Random() |
let N=System.Random() |
||
Line 528: | Line 528: | ||
printf "A well shuffled deck -> "; List.iter (printf "%s ") fN; printfn "" |
printf "A well shuffled deck -> "; List.iter (printf "%s ") fN; printfn "" |
||
fN |> List.chunkBySize 2 |> List.groupBy List.head |> List.iter(fun(n,n')->printfn "The %s pile contains %s" n (fG n')) |
fN |> List.chunkBySize 2 |> List.groupBy List.head |> List.iter(fun(n,n')->printfn "The %s pile contains %s" n (fG n')) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 537: | Line 537: | ||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
< |
<syntaxhighlight lang="factor">USING: accessors combinators.extras formatting fry |
||
generalizations io kernel math math.ranges random sequences |
generalizations io kernel math math.ranges random sequences |
||
sequences.extras ; |
sequences.extras ; |
||
Line 589: | Line 589: | ||
test-assertion ; ! step 4 |
test-assertion ; ! step 4 |
||
MAIN: main</ |
MAIN: main</syntaxhighlight> |
||
A run: |
A run: |
||
{{out}} |
{{out}} |
||
Line 644: | Line 644: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 721: | Line 721: | ||
fmt.Println("So the asssertion is incorrect!") |
fmt.Println("So the asssertion is incorrect!") |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 769: | Line 769: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
< |
<syntaxhighlight lang="haskell">import System.Random (randomRIO) |
||
import Data.List (partition) |
import Data.List (partition) |
||
import Data.Monoid ((<>)) |
import Data.Monoid ((<>)) |
||
Line 836: | Line 836: | ||
replaceAt i c l = |
replaceAt i c l = |
||
let (a, b) = splitAt i l |
let (a, b) = splitAt i l |
||
in a ++ c : drop 1 b</ |
in a ++ c : drop 1 b</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>Discarded: RRRRRBBBBBRBBBRBBRBRRBRRRB |
<pre>Discarded: RRRRRBBBBBRBBBRBBRBRRBRRRB |
||
Line 848: | Line 848: | ||
=={{header|J}}== |
=={{header|J}}== |
||
The trick verb returns 0 if the magician's proposition fails, otherwise 1. |
The trick verb returns 0 if the magician's proposition fails, otherwise 1. |
||
<syntaxhighlight lang="j"> |
|||
<lang J> |
|||
NB. A failed assertion looks like this |
NB. A failed assertion looks like this |
||
assert 0 |
assert 0 |
||
|assertion failure: assert |
|assertion failure: assert |
||
| assert 0 |
| assert 0 |
||
</ |
</syntaxhighlight> |
||
We find that in three runs the trick works. |
We find that in three runs the trick works. |
||
<syntaxhighlight lang="j"> |
|||
<lang J> |
|||
shuffle =: {~ ?~@:# |
shuffle =: {~ ?~@:# |
||
f =: (,&.> {:)~ |
f =: (,&.> {:)~ |
||
Line 903: | Line 903: | ||
black pile BrrBrrrBBrr |
black pile BrrBrrrBBrr |
||
red pile rBrBrBBrBBBBBBB |
red pile rBrBrBBrBBBBBBB |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Javascript}}== |
=={{header|Javascript}}== |
||
{{trans|Haskell}} |
{{trans|Haskell}} |
||
< |
<syntaxhighlight lang="javascript">(() => { |
||
'use strict'; |
'use strict'; |
||
Line 1,068: | Line 1,068: | ||
// MAIN --- |
// MAIN --- |
||
return main(); |
return main(); |
||
})();</ |
})();</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>Discarded: BRBRBRRRRBBBRBBBRBBBBBRRBR |
<pre>Discarded: BRBRBRRRRBBBRBBBRBBBBBRRBR |
||
Line 1,080: | Line 1,080: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
< |
<syntaxhighlight lang="julia">const rbdeck = split(repeat('R', 26) * repeat('B', 26), "") |
||
shuffledeck() = shuffle(rbdeck) |
shuffledeck() = shuffle(rbdeck) |
||
Line 1,131: | Line 1,131: | ||
mindbogglingcardtrick(false) |
mindbogglingcardtrick(false) |
||
end |
end |
||
</ |
</syntaxhighlight>{{output}}<pre> |
||
Shuffled deck is: SubString{String}["B", "B", "R", "B", "B", "R", "B", "R", "B", "R", "B", "B", "B", "R", "B", "R", "R", "B", "R", "R", |
Shuffled deck is: SubString{String}["B", "B", "R", "B", "B", "R", "B", "R", "B", "R", "B", "B", "B", "R", "B", "R", "R", "B", "R", "R", |
||
"R", "R", "R", "R", "B", "R", "B", "B", "B", "R", "R", "B", "B", "R", "B", "B", "R", "R", "B", "R", "R", "R", "R", "B", "B", "R", "B", |
"R", "R", "R", "R", "B", "R", "B", "B", "B", "R", "R", "B", "B", "R", "B", "B", "R", "R", "B", "R", "R", "R", "R", "B", "B", "R", "B", |
||
Line 1,170: | Line 1,170: | ||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="scala">// Version 1.2.61 |
||
import java.util.Random |
import java.util.Random |
||
Line 1,231: | Line 1,231: | ||
println("So the asssertion is incorrect!") |
println("So the asssertion is incorrect!") |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{output}} |
{{output}} |
||
Line 1,279: | Line 1,279: | ||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
< |
<syntaxhighlight lang="lua">-- support: |
||
function T(t) return setmetatable(t, {__index=table}) end |
function T(t) return setmetatable(t, {__index=table}) end |
||
table.range = function(t,n) local s=T{} for i=1,n do s[i]=i end return s end |
table.range = function(t,n) local s=T{} for i=1,n do s[i]=i end return s end |
||
Line 1,329: | Line 1,329: | ||
-- demo: |
-- demo: |
||
math.randomseed(os.time()) |
math.randomseed(os.time()) |
||
for i = 1,3 do cardtrick() end</ |
for i = 1,3 do cardtrick() end</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>1. DECK : RBBBRBRBRBBBBRRRRBRBBBRRBRRBRRBRBBRRBBRRBBRRRBBRBRBR |
<pre>1. DECK : RBBBRBRBRBBBBRRRRBRBBBRRBRRBRRBRBBRRBBRRBBRRRBBRBRBR |
||
Line 1,371: | Line 1,371: | ||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">s = RandomSample@Flatten[{Table[0, 26], Table[1, 26]}] |
||
g = Take[s, {1, -1, 2}] |
g = Take[s, {1, -1, 2}] |
||
d = Take[s, {2, -1, 2}] |
d = Take[s, {2, -1, 2}] |
||
Line 1,386: | Line 1,386: | ||
finala = Join[a[[1]], b[[2]]] |
finala = Join[a[[1]], b[[2]]] |
||
finalb = Join[b[[1]], a[[2]]] |
finalb = Join[b[[1]], a[[2]]] |
||
Count[finala, 1] == Count[finalb, 0]</ |
Count[finala, 1] == Count[finalb, 0]</syntaxhighlight> |
||
{{output}} |
{{output}} |
||
Line 1,408: | Line 1,408: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
< |
<syntaxhighlight lang="nim">import random, sequtils, strformat, strutils |
||
type Color {.pure.} = enum Red = "R", Black = "B" |
type Color {.pure.} = enum Red = "R", Black = "B" |
||
Line 1,460: | Line 1,460: | ||
echo "So the asssertion is correct." |
echo "So the asssertion is correct." |
||
else: |
else: |
||
echo "So the asssertion is incorrect."</ |
echo "So the asssertion is incorrect."</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,485: | Line 1,485: | ||
Trying several non-random deck orderings, in addition to a shuffled one. Predictably, the trick always works. |
Trying several non-random deck orderings, in addition to a shuffled one. Predictably, the trick always works. |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
< |
<syntaxhighlight lang="perl">sub trick { |
||
my(@deck) = @_; |
my(@deck) = @_; |
||
my $result .= sprintf "%-28s @deck\n", 'Starting deck:'; |
my $result .= sprintf "%-28s @deck\n", 'Starting deck:'; |
||
Line 1,528: | Line 1,528: | ||
print trick(@deck); |
print trick(@deck); |
||
@deck = sort { -1 + 2*int(rand 2) } @deck; # poor man's shuffle |
@deck = sort { -1 + 2*int(rand 2) } @deck; # poor man's shuffle |
||
print trick(@deck);</ |
print trick(@deck);</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Starting deck: R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B |
<pre>Starting deck: R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B R B |
||
Line 1,559: | Line 1,559: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
||
<span style="color: #008080;">constant</span> <span style="color: #000000;">n</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">52</span><span style="color: #0000FF;">,</span> |
<span style="color: #008080;">constant</span> <span style="color: #000000;">n</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">52</span><span style="color: #0000FF;">,</span> |
||
Line 1,594: | Line 1,594: | ||
<span style="color: #004080;">string</span> <span style="color: #000000;">correct</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">nr</span><span style="color: #0000FF;">==</span><span style="color: #000000;">nb</span><span style="color: #0000FF;">?</span><span style="color: #008000;">"correct"</span><span style="color: #0000FF;">:</span><span style="color: #008000;">"**INCORRECT**"</span><span style="color: #0000FF;">)</span> |
<span style="color: #004080;">string</span> <span style="color: #000000;">correct</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">nr</span><span style="color: #0000FF;">==</span><span style="color: #000000;">nb</span><span style="color: #0000FF;">?</span><span style="color: #008000;">"correct"</span><span style="color: #0000FF;">:</span><span style="color: #008000;">"**INCORRECT**"</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d r in red, %d b in black - assertion %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">nr</span><span style="color: #0000FF;">,</span><span style="color: #000000;">nb</span><span style="color: #0000FF;">,</span><span style="color: #000000;">correct</span><span style="color: #0000FF;">})</span> |
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d r in red, %d b in black - assertion %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">nr</span><span style="color: #0000FF;">,</span><span style="color: #000000;">nb</span><span style="color: #0000FF;">,</span><span style="color: #000000;">correct</span><span style="color: #0000FF;">})</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,610: | Line 1,610: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
The code is layed out to follow the task decription, leading to some deviations from the PEP8 ''guidelines'' |
The code is layed out to follow the task decription, leading to some deviations from the PEP8 ''guidelines'' |
||
< |
<syntaxhighlight lang="python">import random |
||
## 1. Cards |
## 1. Cards |
||
Line 1,658: | Line 1,658: | ||
print('Yeha! The mathematicians assertion is correct.') |
print('Yeha! The mathematicians assertion is correct.') |
||
else: |
else: |
||
print('Whoops - The mathematicians (or my card manipulations) are flakey')</ |
print('Whoops - The mathematicians (or my card manipulations) are flakey')</syntaxhighlight> |
||
A run. |
A run. |
||
Line 1,676: | Line 1,676: | ||
=={{header|Quackery}}== |
=={{header|Quackery}}== |
||
< |
<syntaxhighlight lang="quackery"> [ stack ] is discards ( --> s ) |
||
[ stack ] is red-card ( --> s ) |
[ stack ] is red-card ( --> s ) |
||
[ stack ] is black-card ( --> s ) |
[ stack ] is black-card ( --> s ) |
||
Line 1,710: | Line 1,710: | ||
else [ say "false." ] cr cr ] is task ( --> ) |
else [ say "false." ] cr cr ] is task ( --> ) |
||
5 times task</ |
5 times task</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,735: | Line 1,735: | ||
=={{header|R}}== |
=={{header|R}}== |
||
<syntaxhighlight lang="r"> |
|||
<lang R> |
|||
magictrick<-function(){ |
magictrick<-function(){ |
||
deck=c(rep("B",26),rep("R",26)) |
deck=c(rep("B",26),rep("R",26)) |
||
Line 1,775: | Line 1,775: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{Out}} |
{{Out}} |
||
<pre> |
<pre> |
||
Line 1,798: | Line 1,798: | ||
{{works with|Rakudo|2018.08}} |
{{works with|Rakudo|2018.08}} |
||
<lang |
<syntaxhighlight lang="raku" line># Generate a shuffled deck |
||
my @deck = shuffle; |
my @deck = shuffle; |
||
put 'Shuffled deck: ', @deck; |
put 'Shuffled deck: ', @deck; |
||
Line 1,844: | Line 1,844: | ||
@r[@ri] = @bs; |
@r[@ri] = @bs; |
||
@b[@bi] = @rs; |
@b[@bi] = @rs; |
||
}</ |
}</syntaxhighlight> |
||
{{out|Sample output}} |
{{out|Sample output}} |
||
<pre>Shuffled deck: B B B R B R R R B B R R R B R B R B R R R B R B B R R B B R R B R B R R R R B R R B B B B B B R R B B B |
<pre>Shuffled deck: B B B R B R R R B B R R R B R B R B R R R B R B B R R B B R R B R B R R R R B R R B B B B B B R R B B B |
||
Line 1,877: | Line 1,877: | ||
Extra coding was added to keep ''singularities'' (opposite of a plural) to keep the English gooder (''sic''), as well as |
Extra coding was added to keep ''singularities'' (opposite of a plural) to keep the English gooder (''sic''), as well as |
||
<br>adding commas to larger numbers. |
<br>adding commas to larger numbers. |
||
< |
<syntaxhighlight lang="rexx">/*REXX pgm mimics a boggling card trick; separates cards into 3 piles based on color ···*/ |
||
parse arg trials # shuffs seed . /*obtain optional arguments from the CL*/ |
parse arg trials # shuffs seed . /*obtain optional arguments from the CL*/ |
||
if trials=='' | trials=="," then trials= 1000 /*Not specified? Then use the default.*/ |
if trials=='' | trials=="," then trials= 1000 /*Not specified? Then use the default.*/ |
||
Line 1,926: | Line 1,926: | ||
/*"blacks" " " " */ Bc= Bc word(B, B?); B= delword(B, B?, 1) /* " " */ |
/*"blacks" " " " */ Bc= Bc word(B, B?); B= delword(B, B?, 1) /* " " */ |
||
end /*?($)*/ |
end /*?($)*/ |
||
R=R Bc; B=B Rc; return /*add swapped cards to piles.*/</ |
R=R Bc; B=B Rc; return /*add swapped cards to piles.*/</syntaxhighlight> |
||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |
||
Line 1,933: | Line 1,933: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
< |
<syntaxhighlight lang="ruby">deck = ([:black, :red] * 26 ).shuffle |
||
black_pile, red_pile, discard = [], [], [] |
black_pile, red_pile, discard = [], [], [] |
||
Line 1,952: | Line 1,952: | ||
Drumroll... |
Drumroll... |
||
There were #{red_pile.count( :red )}!" |
There were #{red_pile.count( :red )}!" |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre>The magician predicts there will be 5 red cards in the other pile. |
<pre>The magician predicts there will be 5 red cards in the other pile. |
||
Line 1,961: | Line 1,961: | ||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
{{libheader|rand}} |
{{libheader|rand}} |
||
< |
<syntaxhighlight lang="rust">extern crate rand; // 0.5.5 |
||
use rand::Rng; |
use rand::Rng; |
||
use std::iter::repeat; |
use std::iter::repeat; |
||
Line 2,020: | Line 2,020: | ||
println!("Number of black cards in black stack: {}", num_black); |
println!("Number of black cards in black stack: {}", num_black); |
||
println!("Number of red cards in red stack: {}", num_red); |
println!("Number of red cards in red stack: {}", num_red); |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,031: | Line 2,031: | ||
{{trans|Go}} |
{{trans|Go}} |
||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
< |
<syntaxhighlight lang="ecmascript">import "random" for Random |
||
import "/fmt" for Fmt |
import "/fmt" for Fmt |
||
Line 2,102: | Line 2,102: | ||
} else { |
} else { |
||
System.print("So the asssertion is incorrect!") |
System.print("So the asssertion is incorrect!") |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,127: | Line 2,127: | ||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
< |
<syntaxhighlight lang="zkl">cards:=[1..52].pump(List,"isEven","toInt").shuffle(); // red==1 |
||
stacks:=T(List(),List()); // black stack [0], red stack [1] |
stacks:=T(List(),List()); // black stack [0], red stack [1] |
||
blkStk,redStk := stacks; |
blkStk,redStk := stacks; |
||
Line 2,144: | Line 2,144: | ||
else println("Boo, different stack lenghts"); |
else println("Boo, different stack lenghts"); |
||
fcn redBlack(cards){ cards.pump(String,fcn(c){ c and "R " or "B " }) }</ |
fcn redBlack(cards){ cards.pump(String,fcn(c){ c and "R " or "B " }) }</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |