Mind boggling card trick: Difference between revisions

Added AppleScript.
(Added AppleScript.)
Line 82:
Yeha! The mathematicians assertion is correct.
</pre>
 
=={{header|AppleScript}}==
<lang applescript>on cardTrick()
set suits to {"♥️", "♣️", "♦️", "♠️"}
set cards to {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"}
set deck to {}
repeat with s from 1 to (count suits)
set suit to item s of suits
repeat with c from 1 to (count cards)
set end of deck to item c of cards & suit
end repeat
end repeat
shuffle(deck)
set {blackPile, redPile, discardPile} to {{}, {}, {}}
repeat with c from 1 to (count deck) by 2
set topCard to item c of deck
if (character -1 of topCard is in "♣️♠️") then
set end of blackPile to item (c + 1) of deck
else
set end of redPile to item (c + 1) of deck
end if
set end of discardPile to topCard
end repeat
set {redBunch, blackBunch} to {{}, {}}
set maxRand to (count blackPile)
tell (count redPile) to if (it < maxRand) then set maxRand to it
set X to (random number from 1 to maxRand)
repeat X times
set c to (random number from 1 to maxRand)
set end of redBunch to text c of redPile
set text c of redPile to missing value
set c to (random number from 1 to maxRand)
set end of blackBunch to text c of blackPile
set text c of blackPile to missing value
set maxRand to maxRand - 1
end repeat
set blackPile to (blackPile's text) & redBunch
set redPile to (redPile's text) & blackBunch
set blacksInBlackPile to 0
repeat with card in blackPile
if (character -1 of card is in "♣️♠️") then set blacksInBlackPile to blacksInBlackPile + 1
end repeat
set redsInRedPile to 0
repeat with card in redPile
if (character -1 of card is in "♥️♦️") then set redsInRedPile to redsInRedPile + 1
end repeat
return {truth:(blacksInBlackPile = redsInRedPile), reds:redPile, blacks:blackPile, discards:discardPile}
end cardTrick
 
on shuffle(array)
repeat with i from (count array) to 2 by -1
set j to (random number from 1 to i)
if (j < i) then
tell array's item i
set array's item i to array's item j
set array's item j to it
end tell
end if
end repeat
return array
end shuffle
 
on join(lst, delim)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to delim
set txt to lst as text
set AppleScript's text item delimiters to astid
return txt
end join
 
on task()
set output to {}
repeat with i from 1 to 10
set {truth:truth, reds:reds, blacks:blacks, discards:discards} to cardTrick()
set end of output to "Test " & i & ": Assertion is " & truth
set end of output to "Red pile: " & join(reds, ", ")
set end of output to "Black pile: " & join(blacks, ", ")
set end of output to "Discards: " & join(items 1 thru 13 of discards, ", ")
set end of output to " " & (join(items 14 thru 26 of discards, ", ") & linefeed)
end repeat
return text 1 thru -2 of join(output, linefeed)
end task
task()</lang>
 
{{output}}
<lang applescript>"Test 1: Assertion is true
Red pile: 8♥️, 5♠️, 9♥️, K♣️, J♣️, 10♣️, A♠️, Q♥️, Q♠️, 2♥️, 5♣️, 3♣️, 2♠️, 2♦️
Black pile: K♥️, 9♠️, 8♠️, 10♦️, 7♣️, 2♣️, A♣️, 3♦️, 7♦️, 10♥️, J♥️, K♦️
Discards: A♦️, 4♣️, 4♥️, 3♠️, Q♦️, 6♣️, 6♥️, J♠️, 6♠️, 5♥️, 4♠️, K♠️, 6♦️
9♦️, 7♥️, J♦️, A♥️, 8♣️, 7♠️, Q♣️, 10♠️, 3♥️, 4♦️, 5♦️, 8♦️, 9♣️
 
Test 2: Assertion is true
Red pile: A♣️, K♠️, J♠️, 2♦️, 7♦️, K♣️, 5♦️, 4♣️, 7♠️, 4♥️, 5♥️, 7♣️, 8♣️
Black pile: 3♦️, 9♥️, 6♣️, K♥️, Q♥️, 10♠️, 10♣️, 2♥️, 6♠️, 8♥️, 2♠️, 6♥️, 6♦️
Discards: K♦️, 10♥️, J♣️, A♦️, 5♣️, 9♠️, 8♦️, Q♦️, 9♣️, 7♥️, A♥️, 5♠️, Q♠️
8♠️, A♠️, 9♦️, 4♠️, Q♣️, 2♣️, 10♦️, 3♥️, 4♦️, J♦️, 3♠️, 3♣️, J♥️
 
Test 3: Assertion is true
Red pile: Q♦️, K♦️, J♥️, 5♥️, 3♠️, 2♦️, 2♣️, 9♠️, 7♦️, 3♥️, 7♠️, 3♣️, 10♠️
Black pile: 6♥️, 9♦️, 6♠️, 10♣️, 4♥️, 7♥️, A♠️, J♠️, 4♠️, A♥️, K♣️, 10♦️, 7♣️
Discards: 6♣️, 4♦️, Q♠️, 5♦️, J♣️, K♠️, Q♥️, A♣️, J♦️, 8♠️, 4♣️, 8♣️, 10♥️
5♣️, 2♥️, 6♦️, 8♥️, 9♣️, 9♥️, Q♣️, 3♦️, 2♠️, A♦️, K♥️, 5♠️, 8♦️
 
Test 4: Assertion is true
Red pile: 10♥️, J♣️, 5♣️, 9♦️, 9♣️, A♠️, K♥️, 3♠️, 3♣️, 5♦️, A♥️, 6♠️, 7♥️, Q♦️
Black pile: 8♣️, 4♦️, A♦️, A♣️, 6♦️, K♠️, 7♣️, K♣️, 10♦️, K♦️, J♠️, Q♠️
Discards: 5♠️, 9♥️, 7♦️, Q♥️, 5♥️, 7♠️, 4♥️, 8♠️, J♦️, 2♥️, 9♠️, 10♣️, 6♣️
2♦️, 10♠️, 8♥️, 3♦️, 2♣️, 6♥️, 4♠️, J♥️, 4♣️, 3♥️, 2♠️, 8♦️, Q♣️
 
Test 5: Assertion is true
Red pile: Q♥️, Q♠️, K♥️, 9♠️, 3♠️, 4♦️, A♦️, 8♣️, 4♥️, A♥️, 7♦️
Black pile: 8♥️, 2♥️, 7♥️, 4♣️, 8♦️, Q♣️, 2♦️, 3♣️, 5♣️, 8♠️, 9♦️, 3♦️, 4♠️, 7♣️, K♦️
Discards: 5♠️, 5♦️, 6♠️, 10♣️, Q♦️, 3♥️, K♣️, 2♠️, J♦️, 6♣️, J♣️, 6♦️, A♠️
K♠️, 6♥️, 10♠️, 9♣️, J♥️, 9♥️, 7♠️, J♠️, 10♥️, 5♥️, 10♦️, 2♣️, A♣️
 
Test 6: Assertion is true
Red pile: 5♥️, 4♥️, 6♥️, 3♦️, 9♣️, J♦️, 6♦️, 3♣️, 3♥️, 10♥️, J♣️, K♠️
Black pile: 4♣️, 5♦️, A♠️, Q♦️, A♦️, 8♥️, A♥️, K♣️, 2♣️, A♣️, 9♦️, 7♠️, J♠️, 10♠️
Discards: 8♠️, 3♠️, J♥️, 2♦️, 8♦️, Q♥️, 8♣️, 4♦️, 7♦️, 7♥️, Q♣️, K♥️, 10♦️
10♣️, 9♠️, 7♣️, 5♠️, Q♠️, 6♠️, 4♠️, 5♣️, 2♥️, 2♠️, 6♣️, K♦️, 9♥️
 
Test 7: Assertion is true
Red pile: 3♦️, K♠️, K♥️, 5♣️, 9♣️, 8♥️, K♦️, 2♥️, 9♥️, 3♥️, 8♣️, 6♥️, 4♠️
Black pile: J♣️, 8♠️, 7♠️, J♦️, Q♣️, 2♦️, A♦️, 10♦️, 6♣️, 5♠️, J♠️, 7♣️, 7♥️
Discards: 10♠️, 6♦️, 5♥️, Q♦️, 5♦️, 3♠️, 9♦️, 10♥️, J♥️, 9♠️, 8♦️, Q♥️, 3♣️
6♠️, 4♥️, 4♦️, A♥️, 2♣️, Q♠️, 4♣️, A♠️, K♣️, 7♦️, A♣️, 2♠️, 10♣️
 
Test 8: Assertion is true
Red pile: 4♥️, 2♣️, Q♦️, 10♣️, 3♥️, 2♦️, K♠️, 9♣️, A♣️, Q♠️, 10♠️, 6♥️
Black pile: 5♦️, 10♦️, K♥️, J♣️, J♥️, 6♣️, 7♠️, 3♦️, 7♥️, 8♦️, 9♠️, A♥️, 3♠️, K♦️
Discards: 8♣️, 7♣️, J♦️, 2♥️, 8♥️, 5♠️, 10♥️, 4♣️, 5♥️, J♠️, A♠️, Q♣️, 9♦️
4♦️, 2♠️, 8♠️, 6♦️, 9♥️, K♣️, A♦️, 5♣️, 3♣️, 4♠️, 7♦️, Q♥️, 6♠️
 
Test 9: Assertion is true
Red pile: 8♦️, 7♣️, 4♠️, 7♠️, 3♠️, 7♥️, A♥️, 9♥️, 9♦️, 8♥️, 5♦️, K♠️, 5♠️, Q♣️, J♦️
Black pile: 8♠️, 10♦️, 9♠️, Q♠️, 7♦️, 10♠️, 3♥️, A♠️, A♣️, 2♣️, 2♠️
Discards: J♥️, 5♣️, 8♣️, 9♣️, 6♦️, Q♥️, 6♠️, 2♥️, 4♥️, 3♣️, 2♦️, 6♥️, J♣️
K♣️, Q♦️, 6♣️, 10♣️, K♥️, 4♦️, 4♣️, K♦️, 3♦️, J♠️, A♦️, 5♥️, 10♥️
 
Test 10: Assertion is true
Red pile: 5♥️, 3♠️, 2♣️, A♥️, 9♥️, 6♠️, 8♥️, 2♦️, 3♣️
Black pile: 8♦️, 2♠️, 4♦️, 6♦️, 6♥️, J♠️, J♥️, A♠️, 7♦️, 10♦️, 9♦️, 2♥️, K♦️, Q♠️, J♦️, A♦️, A♣️
Discards: 9♣️, J♣️, 5♠️, 7♣️, 10♣️, 8♣️, 10♠️, 3♥️, K♣️, 4♠️, Q♥️, 6♣️, 8♠️
7♠️, Q♦️, 9♠️, 3♦️, 5♣️, Q♣️, 7♥️, 5♦️, K♥️, 4♣️, 4♥️, K♠️, 10♥️"</lang>
 
=={{header|AutoHotkey}}==
557

edits