Computing magic

Suits of cards on a laptop screen

A clever use of mathematics can mystify audiences. A variety of resources divulge such secrets for a budding mathematically-inclined magician. Colm Mulcahy’s (Spelman College) column Card Colm on MAA Online reveals the mathematics behind a variety of tricks that involve such topics as Fibonacci numbers and results of Paul Erdös. Mathemagician Art Benjamin (Harvey Mudd College) unveils secrets of rapid mental calculation in his book, Secrets of Mental Math. How magical such tricks appear is correlated to one’s insight into the underlying mathematics.

Many math-based card tricks exist on YouTube. I’m fond of math-based magic. My fondness is proportional to my inability to do any magic that isn’t self-working. Simply put, I like the math but I like that the math makes me look magical. Further, magic can engage audiences of many ages. Here you see a picture of Tanya Chartier engaging a youth with card magic trick at the National Museum of Mathematics’ New York City Math Festival in 2019.

Want to be a mathematical card magician? YouTube is a trove of tricks. Here is a fun (self-working) one (with a short video):

As with any trick I see, my initial reaction is, “Wow! That’s amazing!” I can sense the math but am overtaken with the mystery. An attribute of a self-working trick is only the steps need to be remembered – the magic takes care of itself.

Try the trick in the magic in the video. It works — every time regardless of the order of the deck. And then comes the real trick — after the initial “Wow” comes the desire to understand. Why does the trick work and this is when the magic turns to math. Not surprisingly, trick relies on placing the chosen card ninth from the bottom. There are 52 cards so the chosen card is 43 from the top.

First, imagine capping all four piles of 10 cards. Then, each pile contains 11 cards and the last pile IS capped with the chosen card. However, in every other case, the trick works as outlined in the video. Sum the cards that are face up and count that many cards down. If the sum is 10, for example, the tenth card dealt will be the chosen card. Why does the trick work? I’m going to leave that to your mathematical exploration, mainly due to my repeated inability at writing a clear, succinct answer.

Unless you cap all four piles, you are able to add up the sum of the cards that are face up and count that many cards down to unveil the chosen card. If you cap all four piles, there are no cards face up. In such a case, the “zero” card (rather than the first or thirteenth card, for instance) is the chosen card. Granted, a magician, such as yourself, could finesse unveiling such a “zero card,” which would be the card to cap the fourth pile. In my mind, this is less magical than counting down and finding the chosen card. I found myself wondering, “What is the probability of this even happening?” Feeling quite nerdy but not minding (much), I grabbed a pencil and paper and begin trying to compute such a probability. Soon, it appeared I would need to cover several cases or sit until I perceived another approach. Then, I laughed in the realization, “I’m a mathematician and computer scientist! Let the computer do the computing!”

I quickly coded a program to perform the trick. I created a deck and randomly permuted the cards to serve as my shuffle. Then, I simply performed the trick 100,000 times keeping track of how often I capped all four piles in the trick. The first time I ran the computation, this occurred 1352 times. The second time I (via my program) performed the trick 100,000 times capping all four piles 1336 times.

So, I would have about a 1.3% chance of capping all four decks. Given I rarely perform magic, this is a pretty small chance. If I decided to perform the trick more often, could I live with that probability? Would you? It may partially depend on what you do when the case arises. Frankly, I might just put the chosen card as the 8th card from the bottom and then count down the desired number of cards and the next card is your card. In such a case, if every deck is capped, the next card is your card. The math is easier to perceive though…But, I often perform math-based magic tricks so people can learn and struggle with the math. Yet, maybe that’s precisely why the original trick is compelling! I, for instance, sat and coded a computer program to perform the trick, and am now blogging about it! Were the card the 8th from the bottom, maybe once I saw the trick, I might have even forgotten about it several hours later. I guess, now that I think about it, I can live with that 1.3% chance in the hopes that someone else might enjoy a similar mathematical journey. And then again, maybe I’m the only one who might not be that great at finessing a zeroth card!

What choice would you make?