Math behind a card trick

ScoobyDue's avatar - animaniacs31

I saw a card trick once that was pretty cool.

I've since used it hundreds of times to win free drinks at the bar and have often wondered about the mathematics behind the trick.

It's amazingly reliable but not fallible as I have had to buy a few drinks along the way.


The trick goes like this:

Take a shuffled deck and ask the participant to name 2 values of cards (suits do not matter).

Let's say Jack & 6.

You then predict that you will find their cards either right next to each other or only one card apart.

Try it!

I'm guessing it has worked for me probably 95% of the time.

I'd like to know the actual % of certainty that this will occur.

One caveat that I introduced that has saved me a few times is that the deck "wraps" around.

So the top card is considered right next to the bottom card.

Thanks for you wizards insight on this.

ScoobyDue's avatar - animaniacs31

I guess I should've said it's not infallible but I can't figure out how to edit

cottoneyedjoe's avatar - cuonvFT

Letting the deck cycle through helps. Think of every jack as having a 4-card neighborhood. If the jacks are sufficiently far enough apart so that none of the neighborhoods overlap, then the maximum number of cards that can belong to a jack neighborhood is 16. That means the minimum number of cards that do not belong to a jack neighborhood is 32. Let's call these cards the "outskirts."

The probability that none of the 6s are in a jack neighborhood is equal to the probability that all of them are in the outskirts. When there are 32 cards in the outskirts, this is 

(32 choose 4)/(48 choose 4) = 1798/9729 ≈ 18.48%

And so the probability that at least one 6 is in a jack neighborhood is about 81.52%. The reason why the denominator is not (52 choose 4) is because the four jacks are like anchors, neither in a neighborhood or the outskirts. A 6 cannot occupy the same position as a jack.

Now, there are cases when the jacks are too close together and some neighborhoods overlap, which makes the neighborhood size less than 16, which makes the probability of success lower. In the most extreme case, all four jacks are next to each other and the total neighborhood is only four cards. It's a lot of work to analyze all these sub cases, so think of 81.52% as an upper bound. I can write a script later to simulate a couple million random shuffles and give you a better estimate of the true probability, but I hope this has been of help.


Thanks for the food for thought. May the free booze keep flowing.

ScoobyDue's avatar - animaniacs31


That was way better of an explanation than I could have hoped for.

Don't work too hard to calculate all the answers.  You've given me all I need to know.

I was always fascinated by the math behind the challenge but could never put a pencil to it.

cottoneyedjoe's avatar - cuonvFT
In response to ScoobyDue

it's not too much trouble, I like these sorts of probability problems. I did 10 million simulations of a shuffled deck and got a success rate of 74.76% for your trick with wrap around, which makes sense in light of the probabilities of the jack-neighborhood sizes -- a 16-card jack-neighborhood size occurs in only about 31% of shuffles, while the average size is about 13.7 cards. I ran 5 million simulations to approximate the probabilities of getting all the different neighborhood sizes from a min of 4 to a max of 16:

  • neighborhood size: probability
  • 4 cards: 0.0185% <--- all four jacks next to each other
    5 cards: 0.05816%
    6 cards: 0.1171%
    7 cards: 0.19342%
    8 cards: 1.40916%
    9 cards: 2.52698%
    10 cards: 3.57384%
    11 cards: 4.50628%
    12 cards: 16.76448%
    13 cards: 14.86646%
    14 cards: 13.12884%
    15 cards: 11.43872%
    16 cards: 31.39806%

In general the larger the neighborhood the higher the probability, except for the range 12 to 15. It seems counterintuitive that the probabilities of the neighborhood sizes for 12 to 15 cards run the opposite direction, but if you think about it, it requires a very specific arrangement to get a 15-card neighborhood, you have to have one pair of jacks exactly three cards apart, and then there's a little more wiggle room as you go from 14 to 12. And there's a big drop off in probability between sizes 11 and 12, again because it requires one very specific arrangement to get an 11 card neighborhood size.

If you multiply the probability of each N-card neighborhood size by 1 - (48-N choose 4)/(48 choose 4), which is the probability of getting at least one 6 in a jack neighborhood, and add them all up, you again get a success rate of about 74.75%. So I'm going to put it to bed and conclude that is approximately the theoretical success rate of your trick.

Now you just have to come up with a trick with a higher success rate that your marks don't know is rigged in your favor.

Good night!

TopEnd of thread (1 page)

Welcome Guest

Your last visit: Sat, Nov 28, 2020, 7:44 pm

Log In

Log InCancel

Forgot your username?

Forgot your password?