LibraryQuant puzzles
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?
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.
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.
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
The ace of spades had nothing to do with it. Every ordinary card is between the jokers with probability 1/3.
Now write when card lies between the jokers and otherwise, and let 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 is zero at once). So
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.
The follow-up an interviewer asks next is the general one. With jokers shuffled into ordinary cards, the jokers cut the row into blocks and each ordinary card is equally likely to fall in any of them, so every block averages . Two jokers and 52 cards is the case . One joker gives 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.
52/3 cards, about 17.33.
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