LibraryQuant puzzles

Expected Cards Between the Two Jokers

Quant puzzle · intro · free, full solution

The question

Take a deck of 54 cards: the usual 52 plus two jokers. Shuffle it so that all orderings are equally likely, and lay the cards out in a row.

Count the ordinary cards lying strictly between the two jokers. If the jokers happen to land side by side that count is zero, and if one joker is first in the row and the other is last the count is 52.

What is the expected value of that count?

Hint

Placing both jokers first and summing over the gaps works but is heavy. Look for a smaller question whose answer is the same for every ordinary card in the deck.

The idea behind it

Ask about one ordinary card at a time. Relative to the two jokers it is equally likely to be before, between, or after, so it counts with probability one third. Linearity of expectation then adds up fifty two identical answers.

Worked solution

The direct attack is to ask where the first joker lands, then where the second lands given the first, then sum the gaps against a two-dimensional weighting. It can be done. It is also entirely unnecessary.

Instead, pick out one ordinary card, say the ace of spades, and ask a single question about it: is it between the two jokers? Ignore the other 51 ordinary cards completely. That leaves three cards to think about, the ace and the two jokers, and the shuffle makes all six orderings of those three equally likely. In two of the six the ace sits in the middle. So

P(the ace of spades lies between the jokers)=26=13P(\text{the ace of spades lies between the jokers}) = \frac{2}{6} = \frac{1}{3}

The ace of spades had nothing to do with it. Every ordinary card is between the jokers with probability 1/3.

Now write Ic=1I_c = 1 when card cc lies between the jokers and Ic=0I_c = 0 otherwise, and let N=∑cIcN = \sum_c I_c be the count we want, the sum running over all 52 ordinary cards. Expectation of a sum is the sum of expectations, whether or not the terms are independent (they are not: if the jokers land next to each other, every single IcI_c is zero at once). So

E[N]=52×13=523≈17.33\mathbb{E}[N] = 52 \times \frac{1}{3} = \frac{52}{3} \approx 17.33

The check that makes this feel right rather than merely correct: the two jokers cut the row into three blocks, the cards before the first joker, the cards between, and the cards after the second. By the same three-card argument each ordinary card is equally likely to be in any of the three, so all three blocks average 52/3, and the three averages add back to 52. The deck splits evenly in expectation even though it almost never splits evenly in fact.

Stem plot of Chance of this count against Cards between the jokers. 53 points, including 0: 0.037; 13: 0.0279; 26: 0.0189; 39: 0.00978; 52: 0.0007. Reference line Average, 17.33 cards at x = 17.3.Chance of this count0.000.010.020.030.0401020304050Cards between the jokersAverage, 17.33 cardsStem plot of Chance of this count against Cards between the jokers. 53 points, including 0: 0.037; 13: 0.0279; 26: 0.0189; 39: 0.00978; 52: 0.0007. Reference line Average, 17.33 cards at x = 17.3.Chance of this count0.000.010.020.030.0402040Cards between the jokersAverage, 17.33 cards
The count is likeliest when the jokers sit side by side and the chance falls in a straight line from there, so the average of 17.33 cards is far from the likeliest count.

The follow-up an interviewer asks next is the general one. With kk jokers shuffled into nn ordinary cards, the jokers cut the row into k+1k + 1 blocks and each ordinary card is equally likely to fall in any of them, so every block averages n/(k+1)n/(k+1). Two jokers and 52 cards is the case k=2k = 2. One joker gives n/2n/2 on each side, which is obvious and is a useful place to check that the formula is not nonsense.

Worth being precise about one thing, since it is where this argument gets misapplied. The blocks all have the same average size, but they do not have the same distribution as each other in every variant of the problem, and the average of the largest block is nowhere near 52/3. Linearity of expectation buys the mean of a sum and nothing else.

In short

52/3 cards, about 17.33.

Learn quant finance on Thuztra Learn

Thuztra Learn teaches the maths of quant finance from zero, in short lessons, for readers who are unsure of it. Three questions in the app build your quant roadmap, free. Membership is a paid subscription. See what Thuztra Learn is and what it costs, or see the whole Core quant curriculum.

Get the app and answer the three questions:

Download on the Microsoft Store Download for Android

On Android, the app is a direct download, not a Google Play listing. Which devices, and what each one needs.

Further reading

Related problems

Topics

Also in the library