Mind boggling card trick

You are encouraged to solve this task according to the task description, using any language you may know.
Matt Parker of the "Stand Up Maths channel" has a   YouTube video   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   (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   top card   and hold it in your hand.
 if the card is   black,   then add the   next   card (unseen) to the "black" pile. 
 If the card is     red,    then add the   next   card (unseen) to the   "red"  pile.
 Add the   top card   that you're holding to the discard pile.   (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   (call it X)   that will be used to swap cards from the "red" and "black" piles.
 Randomly choose   X   cards from the   "red"  pile (unseen), let's call this the   "red"  bunch. 
 Randomly choose   X   cards from the "black" pile (unseen), let's call this the "black" bunch.
 Put the     "red"    bunch into the   "black" pile.
 Put the   "black"   bunch into the     "red"  pile.
 (The above two steps complete the swap of   X   cards of the "red" and "black" piles. 
 (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: 
     The number of black cards in the "black" pile equals the number of red cards in the "red" pile. 



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

Show output on this page.




deck = ([:black, :red] * 26 ).shuffle
black_pile, red_pile, discard = [] of Symbol, [] of Symbol, [] of Symbol
 
until deck.empty?
  discard << deck.pop
  discard.last == :black ? black_pile << deck.pop : red_pile << deck.pop
end
 
x = rand( [black_pile.size, red_pile.size].min )
 
red_bunch   = (0...x).map { red_pile.delete_at( rand( red_pile.size )) }
black_bunch = (0...x).map { black_pile.delete_at( rand( black_pile.size )) }
 
black_pile += red_bunch
red_pile   += black_bunch
 
puts "The magician predicts there will be #{black_pile.count( :black )} red cards in the other pile.
Drumroll...
There were #{red_pile.count( :red )}!"