Matt Parker of the "Stand Up Maths channel" has a &nbsp; [https://www.youtube.com/watch?v=aNpGxZ_1KXU <u>YouTube video</u>] &nbsp; of a card trick that creates a semblance of order from chaos.

The task is to simulate the trick in a way that mimics the steps shown in the video.

; 1. Cards.
# Create a common deck of cards of 52 cards  &nbsp; (which are half red, half black).
# Give the pack a good shuffle.
; 2. Deal from the shuffled deck, you'll be creating three piles.
#   Assemble the cards face down.
##   Turn up the &nbsp; ''top card'' &nbsp; and hold it in your hand. 
###    if the card is &nbsp;       black,      &nbsp; then add the &nbsp; ''next'' &nbsp; card (unseen) to the       "black"      pile. 
###    If the card is &nbsp; &nbsp; red,&nbsp; &nbsp; then add the &nbsp; ''next'' &nbsp; card (unseen) to the &nbsp; "red"&nbsp; pile.
##   Add the &nbsp; ''top card'' &nbsp; that you're holding to the '''discard''' pile. &nbsp; (You might optionally show these discarded cards to get an idea of the randomness).
# Repeat the above for the rest of the shuffled deck.
; 3. Choose a random number &nbsp; (call it '''X''') &nbsp; that will be used to swap cards from the "red" and "black" piles.
# Randomly choose &nbsp; '''X''' &nbsp; cards from the &nbsp; "red"&nbsp; pile (unseen), let's call this the &nbsp; "red"&nbsp; bunch. 
# Randomly choose &nbsp; '''X''' &nbsp; cards from the       "black"      pile (unseen), let's call this the      "black"       bunch.
# Put the &nbsp; &nbsp; "red"&nbsp; &nbsp; bunch into the &nbsp;       "black"      pile.
# Put the &nbsp;      "black"      &nbsp; bunch into the  &nbsp; &nbsp; "red"&nbsp; pile.
# (The above two steps complete the swap of &nbsp; '''X''' &nbsp; cards of the "red" and "black" piles. <br> (Without knowing what those cards are --- they could be red or black, nobody knows).
; 4. Order from randomness?
# Verify (or not) the mathematician's assertion that: 
     <big> '''The number of black cards in the "black" pile equals the number of red cards in the "red" pile.''' </big>


(Optionally, run this simulation a number of times, gathering more evidence of the truthfulness of the assertion.)

Show output on this page.
<br><br>

