পরিমাণগত অর্থায়ন · বই 18 · ক্যারিয়ার

Interviews I: Maths, Probability and Speed

এই বইটি এখনো বাংলা ভাষায় পাওয়া যায় না। সংস্করণ: English, Français।

Interviews I: Maths, Probability and Speed · ক্যারিয়ার

7Counting and Symmetry

Counting without listing: choosing the right objects to count, subtracting what you overcounted, reflecting paths, and noticing when a symmetry gives the answer with no counting at all. The later questions need a bijection or a group of rotations that you have to find for yourself.

Question 7.1 ★ QR, QT, Trader, Analyst • any • junior

Eight people sit around a round table, and two seatings count as the same if one is a rotation of the other. How many seatings are there? How many keep two particular people from sitting next to each other?

Answer

Answer to Question 7.1.

There are 7!=50407! = 5040 seatings, and 36003600 keep the two apart.

Fix one person’s chair to remove the rotations, and then seat the other seven in order. For the second count, subtract the seatings with the two together. Glue them into a block: that leaves seven objects around the table, which gives 6!6! arrangements, and the block has 2 internal orders. So 5040−2⋅720=36005040 - 2 \cdot 720 = 3600.

Follow-up. What fraction is that? 5/75/7. Seen from one of the two, the other sits in one of seven chairs at random, and two of those are adjacent.

Question 7.2 ★ QR, QT, Trader, Analyst • any • junior

How many distinct arrangements are there of the letters of MISSISSIPPI? In how many of them are no two S’s next to each other?

Answer

Answer to Question 7.2.

There are 34 65034\,650 arrangements, of which 73507350 have no two S’s together.

There are 11 letters, with four I’s, four S’s and two P’s, so the multinomial coefficient gives 11!/(4! 4! 2!)=34 65011!/(4!\,4!\,2!) = 34\,650.

For the second count, place the S’s last. The seven other letters can be arranged in 7!/(4! 2!)=1057!/(4!\,2!) = 105 ways. They leave 8 gaps, counting both ends, and the four S’s go into four different gaps, in (84)=70\binom{8}{4} = 70 ways. The product is 73507350, or 7/337/33 of the total.

Classic wrong answer. Subtracting “arrangements with an SS block” from the total. Blocks overlap in many ways, and the gaps method avoids all of them.

Question 7.3 ★ QR, QT, Trader, QD • any • junior

You walk on a grid from the corner (0,0)(0, 0) to the corner (5,5)(5, 5), with each step going one unit right or one unit up. How many paths are there? How many avoid the point (2,2)(2, 2)?

Answer

Answer to Question 7.3.

There are 252 paths, and 132 avoid the point.

A path is a string of five rights and five ups, so there are (105)=252\binom{10}{5} = 252. Those through (2,2)(2, 2) split into two independent parts, (42)=6\binom{4}{2} = 6 ways to reach it and (63)=20\binom{6}{3} = 20 ways to go on. So 120 pass through it, and 252−120=132252 - 120 = 132 avoid it.

Follow-up. How would you code it for many blocked points? Fill a table by dynamic programming: each cell holds the sum of the cells to its left and below, and zero if blocked.

Question 7.4 ★ QR, QT, Trader, Analyst • any • junior

In how many ways can you put 10 identical coins into 4 labelled boxes? In how many ways if no box may be empty?

Answer

Answer to Question 7.4.

There are 286 ways with empty boxes allowed, and 84 ways with none empty.

Use stars and bars. Line up the 10 coins and put 3 dividers among them. That is a choice of 3 places out of 13, so (133)=286\binom{13}{3} = 286. If no box may be empty, put one coin in each first. That leaves 6 coins to share in any way: (93)=84\binom{9}{3} = 84.

Classic wrong answer. 4104^{10}, which is the answer for labelled coins. Identical coins make the outcome depend only on how many land in each box.

Question 7.5 ★ QR, QT, Trader, Analyst, Risk • any • junior

A committee of 4 is chosen from 6 men and 5 women. How many committees include at least one woman? Why does “choose one woman, and then any 3 of the other 10” give the wrong number?

Answer

Answer to Question 7.5.

There are 315 committees. The shortcut gives 600, because it counts a committee once for each woman in it.

Count the complement: of the (114)=330\binom{11}{4} = 330 committees, (64)=15\binom{6}{4} = 15 are all men, and 330−15=315330 - 15 = 315.

The wrong method names one woman as “the” woman and then chooses the remaining three, giving 5(103)=6005 \binom{10}{3} = 600. A committee with ww women is produced ww times, once for each of them. Adding up the number of women over all committees gives exactly 600.

Why it matters. Whenever a count looks too big, ask how many times each object is produced. That question finds most counting errors.

Question 7.6 ★ QR, QT, Trader • any • junior

You roll five fair dice and look only at which values came up, ignoring the order. How many different results are there? What is the probability of a full house, meaning three of one value and two of another? Why can you not divide by the first number to get it?

Answer

Answer to Question 7.6.

There are 252 different results, and the probability of a full house is 300/7776≈0.0386300/7776 \approx 0.0386.

A result ignoring order is a multiset of 5 values from 6, so stars and bars gives (105)=252\binom{10}{5} = 252.

The results are not equally likely, so you cannot divide by 252. A full house, say 3, 3, 3, 5, 5, arises from (52)=10\binom{5}{2} = 10 ordered rolls, while 1, 2, 3, 4, 5 arises from 120 and five sixes from just one. So count ordered rolls: 6 choices for the triple, 5 for the pair, 10 orders, which is 300 out of 65=77766^5 = 7776.

Classic wrong answer. Dividing by 252 to get 30/252≈0.11930/252 \approx 0.119. Treating unordered results as equally likely is the most common error in this chapter’s topic.

Question 7.7 ★ QR, QT, Trader, Risk • any • junior

An urn holds 5 blue balls and 3 red ones. You draw them all, one at a time, without replacement. What is the probability that the last ball is red? And the second ball?

Answer

Answer to Question 7.7.

Both are 3/83/8.

Use symmetry. Every ordering of the eight balls is equally likely, so every position has the same chance of holding a given ball. Each of the 8 balls is equally likely to be last, and 3 of them are red. The same holds for the second position, and for any other.

Classic wrong answer. Conditioning through all the earlier draws. This works, but it takes a page, and the symmetry makes the order in which balls come out irrelevant. The first ball you see does change the conditional chance for the second, but before you see anything, each position has the same chance.

Question 7.8 ★ QR, QT, Trader, Analyst • any • junior

A cube of side 10 is painted on the outside and cut into 1 000 unit cubes. How many unit cubes have paint on exactly 3, 2, 1 and 0 faces? If you pick one unit cube at random, how many painted faces does it have on average?

Answer

Answer to Question 7.8.

There are 8 with three painted faces, 96 with two, 384 with one and 512 with none. On average a unit cube has 0.60.6 painted faces.

The corners give the 8. Each of the 12 edges has 10−2=810 - 2 = 8 inner cubes, which gives 96. Each of the 6 faces has 82=648^2 = 64 interior squares, which gives 384. The inside is a block of 83=5128^3 = 512. These add to 1 000, which is the check.

For the average, count painted faces from the outside: the big cube has 6 faces of 100 unit squares each, which makes 600 faces. Spread over 1 000 cubes that is 0.60.6.

Follow-up. And for a side of nn? 6n2/n3=6/n6n^2/n^3 = 6/n faces on average.

Question 7.9 ★ QR, QT, Trader, Analyst, Risk • any • junior

A lottery draws 6 numbers from 49, and your ticket holds 6 numbers. What is the probability that exactly 3 of your numbers match? And at least 3?

Answer

Answer to Question 7.9.

Exactly 3 has probability ≈0.0177\approx 0.0177, or about 1 in 57, and at least 3 has probability ≈0.0186\approx 0.0186, or about 1 in 54.

Count the draws by how they split between your 6 numbers and the other 43: the hypergeometric distribution. There are (496)=13 983 816\binom{49}{6} = 13\,983\,816 draws. Exactly 3 matches come from (63)(433)=20⋅12 341=246 820\binom{6}{3}\binom{43}{3} = 20 \cdot 12\,341 = 246\,820 draws. Summing over 3, 4, 5 and 6 matches gives 0.01860.0186.

Classic wrong answer. Using a binomial with p=6/49p = 6/49. Draws are made without replacement, so the matches are not independent. The binomial gives a value near 0.0250.025, too high.

Question 7.10 ★★ QR, QT, Trader, QD • any • junior

How many of the numbers from 1 to 1 000 are divisible by none of 2, 3 and 5?

Answer

Answer to Question 7.10.

There are 266.

Use inclusion-exclusion. Count the multiples of each prime and subtract, then add back those subtracted twice, then remove those added back too often:

1000−(500+333+200)+(166+100+66)−33=266.1000 - (500 + 333 + 200) + (166 + 100 + 66) - 33 = 266.

The middle terms are multiples of 6, 10 and 15, and the last term is multiples of 30.

A quick check is by density. A share 12⋅23⋅45=415\tfrac12 \cdot \tfrac23 \cdot \tfrac45 = \tfrac{4}{15} of whole numbers avoid all three primes, and 1000⋅4/15≈266.71000 \cdot 4/15 \approx 266.7. The same pattern repeats every 30 numbers, with 8 survivors in each block.

Classic wrong answer. Multiplying 500⋅23⋅45500 \cdot \tfrac23 \cdot \tfrac45 with rounding at each step. It happens to be close, but a rounded product is not a count: inclusion-exclusion gives the exact number.

Follow-up. How would you code it for many primes? Sieve up to nn, or walk the 2k2^k subsets of kk primes with the sign of each subset. The subset walk is the better choice when nn is huge and kk is small.

Question 7.11 ★★ QR, QT, Trader, QD • any • junior

You throw 5 labelled balls into 3 labelled boxes, each ball choosing a box uniformly at random. What is the probability that no box is empty?

Answer

Answer to Question 7.11.

The probability is 150/243=50/81≈0.617150/243 = 50/81 \approx 0.617.

Use inclusion-exclusion over the empty boxes. There are 35=2433^5 = 243 assignments. Those missing a particular box number 252^5, and there are three boxes. Those missing two particular boxes number just 1, and there are three pairs. So the count of assignments with no empty box is

35−3⋅25+3⋅1=150.3^5 - 3 \cdot 2^5 + 3 \cdot 1 = 150.

As a check, count by shapes. The box sizes are 3, 1, 1 or 2, 2, 1. There are 3⋅(53)⋅2=603 \cdot \binom{5}{3} \cdot 2 = 60 of the first shape and 3⋅(52)(32)=903 \cdot \binom{5}{2}\binom{3}{2} = 90 of the second, and 60+90=15060 + 90 = 150.

Classic wrong answer. Starting by placing one ball in each box and letting the rest go anywhere: 5⋅4⋅3⋅32=5405 \cdot 4 \cdot 3 \cdot 3^2 = 540, which is more than the total. Any ball could have been the “first” in its box, so each assignment is counted several times.

Follow-up. What else does this compute? It is the same as asking for the chance that a coupon collector with 3 coupons finishes within 5 draws.

Question 7.12 ★★ QR, QT, Trader, Risk • any • junior

Five letters are placed at random in five addressed envelopes, one in each. What is the probability that no letter is in its right envelope? That exactly two are? What does the first probability approach with many letters?

Answer

Answer to Question 7.12.

No letter correct has probability 44/120=11/30≈0.36744/120 = 11/30 \approx 0.367, exactly two correct has probability 20/120=1/620/120 = 1/6, and the first approaches 1/e≈0.3681/e \approx 0.368.

A permutation with no fixed point is a derangement. By inclusion-exclusion,

Dn=n!∑k=0n(−1)kk!,soD5=44,Dnn!→e−1.D_n = n! \sum_{k=0}^{n} \frac{(-1)^k}{k!}, \quad\text{so}\quad D_5 = 44, \quad \frac{D_n}{n!} \to e^{-1}.

The convergence is very fast. Even five letters are within 0.0020.002 of the limit.

For exactly two correct, choose which two, and derange the other three: (52)D3=10⋅2=20\binom{5}{2} D_3 = 10 \cdot 2 = 20.

Classic wrong answer. Thinking the chance of no match must grow or shrink strongly with more letters. There are more letters to match, but each has less chance of matching, and the two effects cancel: the expected number of matches is always one, and the number of matches tends to a Poisson with mean 1.

Follow-up. Is exactly four correct possible? No. If four letters are right, the fifth envelope is the only one left, and the letter must be right too.

Question 7.13 ★★ QR, QT, Trader • market maker, hedge fund • junior

In an election, candidate A receives 6 votes and candidate B receives 4. The votes are counted one by one, in a random order. What is the probability that A is strictly ahead throughout the count, from the first vote on?

Answer

Answer to Question 7.13.

The probability is (6−4)/(6+4)=1/5(6 - 4)/(6 + 4) = 1/5.

This is the ballot theorem, and the proof uses reflection. Of the (104)=210\binom{10}{4} = 210 orders, count the bad ones, where the count is tied at some point. An order that starts with a B vote is bad for sure, since A has to catch up, which leaves a tie. There are (93)=84\binom{9}{3} = 84 such orders.

Now take an order that starts with A and has a tie. Swap A and B votes up to the first tie. This gives an order starting with B, and the swap can be undone. So bad orders starting with A also number 84. The good orders number 210−168=42210 - 168 = 42, and 42/210=1/542/210 = 1/5.

Classic wrong answer. Treating it as “A has more votes, so is usually ahead” and giving a large number. A lead from the very first vote is a strong demand, and it fails whenever B leads early.

Follow-up. And with 60 votes against 40? The chance is the same formula: 20/100=1/520/100 = 1/5. Only the margin as a share of the votes matters, which tells you that the size of the count does not.

Question 7.14 ★★ QR, QT, Trader • hedge fund, market maker, bank • junior

Ten people queue in random order at a kiosk that sells $5 tickets and starts with an empty till. Five of them hold one $5 note and five hold one $10 note. What is the probability that the kiosk never lacks change? What if six hold $5 notes and four hold $10 notes?

Answer

Answer to Question 7.14.

With five of each, the probability is 1/61/6. With six $5 and four $10 notes, it is 3/73/7.

Write a $5 note as an up step and a $10 note as a down step. The till has enough change exactly when the walk never goes below 0. Use reflection on the bad orders: those that touch −1-1. Reflect the part of the walk up to the first touch of −1-1. It then starts from −2-2 and ends at the same point, so bad orders match every path from −2-2 to the end point. For five and five, such a path has six up steps and four down steps, so there are (104)=210\binom{10}{4} = 210 of them, against the total of (105)=252\binom{10}{5} = 252. So 42 are good, which is the Catalan number C5C_5, and 42/252=1/642/252 = 1/6.

The general result for aa fives and bb tens is (a+1−b)/(a+1)(a + 1 - b)/(a + 1). For six and four, 3/73/7: 9090 of the 210 orders.

Classic wrong answer. Assuming that with equal notes the chance is about one half. Having enough change at the very end is automatic, and it is the path before the end that fails.

Why it matters. Reflection is the tool behind pricing a barrier option in a binomial model: a price path that crosses a level is matched with a reflected one that ends elsewhere.

Question 7.15 ★★ QR, QT, Trader • any • junior

You flip 11 fair coins and I flip 10. What is the probability that you get strictly more heads than I do? Find it without any summation.

Answer

Answer to Question 7.15.

The probability is exactly 1/21/2.

Compare after the first ten flips of each. Let XX be your heads in the first 10 and YY mine. By symmetry, P(X>Y)=P(X<Y)=aP(X > Y) = P(X < Y) = a, say, and P(X=Y)=1−2aP(X = Y) = 1 - 2a. You win if X>YX > Y, or if X=YX = Y and your last coin is heads. If X<YX < Y, even a final head gives at most a tie, and a tie is not strictly more. So your chance is a+12(1−2a)=12a + \tfrac12(1 - 2a) = \tfrac12.

A neater version: you have either more heads than I have, or more tails, and never both, because your 11 flips exceed my 10. For a fair coin, heads and tails have the same role, so each has probability 1/21/2.

Classic wrong answer. Thinking the extra coin gives you more than half. It does give you the tie-break, but ties were counted against you to begin with, so the gain only just brings you to one half.

Follow-up. And with a biased coin? The symmetry fails. If heads is more likely than tails, then you win more than half the time, because the event “more heads” is favoured.

Question 7.16 ★★ QR, QT, Trader • hedge fund, market maker • junior

You deal a shuffled 52-card deck face up until the first ace appears. Is the next card more likely to be the ace of spades or the two of clubs? Find the probability of each.

Answer

Answer to Question 7.16.

They are equally likely: each has probability exactly 1/521/52.

Build the shuffled deck in two steps. Take out the card you care about, and shuffle the other 51. Now insert it at a random place, one of the 52 possible gaps.

For the two of clubs: it is “right after the first ace” for exactly one of the 52 gaps, whichever the other 51 cards look like. So its chance is 1/521/52.

For the ace of spades: use the same deal. The other 51 cards contain three aces, and the first of them is somewhere. If you insert the ace of spades right after it, it is the next card after the first ace. If you insert it earlier, it becomes the first ace itself, and it does not follow one. If you insert it later, it does not come next. So exactly one gap works, and again the chance is 1/521/52.

Classic wrong answer. Saying the ace of spades is less likely, because it might have already gone as the first ace, or more likely, because aces cluster. Both feelings are correct about something, but the insertion count settles it.

Why it matters. Building a random object one card at a time from a simpler one often avoids a heavy conditioning, and interviewers look for this kind of step.

Question 7.17 ★★ QR, QT, Trader • any • junior

A shuffled 52-card deck is dealt into four hands of 13 cards each. What is the probability that each hand holds exactly one ace?

Answer

Answer to Question 7.17.

The probability is 39⋅26⋅1351⋅50⋅49≈0.105\frac{39 \cdot 26 \cdot 13}{51 \cdot 50 \cdot 49} \approx 0.105.

Place the aces one by one, thinking of the deck as 52 slots in four hands. The first ace goes anywhere. The second must avoid the 12 other slots in its hand, so it has 39 good slots of the 51 left. The third has 26 good slots of the 50 left, and the fourth 13 of the 49 left.

The other route is by counting whole deals. The number of deals where each hand has an ace is 4!(4812)(3612)(2412)4!\binom{48}{12}\binom{36}{12}\binom{24}{12}, against (5213)(3913)(2613)\binom{52}{13}\binom{39}{13}\binom{26}{13} deals in all. It reduces to the same fraction, with a good deal more cancelling.

Classic wrong answer. The independent answer, 4!/44≈0.0944!/4^4 \approx 0.094. This treats each ace as choosing a hand independently, and it misses the fact that a hand holding an ace has less room for the next.

Follow-up. Which method carries further? Placing special cards one by one works whenever the special cards are few. Counting deals is better when you must control many cards at once.

Question 7.18 ★★ QR, QT, Trader • any • junior

You roll three fair dice. In how many of the 216 outcomes is the sum 10, and in how many is it 11? Why must those be equal? Then find the number of outcomes with sum 14 for four dice, without listing them.

Answer

Answer to Question 7.18.

Both sums have 27 outcomes, and sum 14 on four dice has 146.

Listing unordered triples for 10 gives (1,3,6)(1,3,6), (1,4,5)(1,4,5), (2,2,6)(2,2,6), (2,3,5)(2,3,5), (2,4,4)(2,4,4), (3,3,4)(3,3,4), with 6,6,3,6,3,36, 6, 3, 6, 3, 3 orders, which is 27. They are equal by a symmetry of the die: replacing each face xx by 7−x7 - x is a bijection of outcomes that sends a sum ss to 21−s21 - s, and 21−10=1121 - 10 = 11.

For four dice, use stars and bars with inclusion-exclusion. Writing di=1+yid_i = 1 + y_i, you need y1+y2+y3+y4=10y_1 + y_2 + y_3 + y_4 = 10 with yi≤5y_i \le 5. With no ceiling that has (133)=286\binom{13}{3} = 286 solutions. If one yi≥6y_i \ge 6, take away 6 from it and count solutions of a sum to 4: (73)=35\binom{7}{3} = 35, for each of 4 dice. Two cannot exceed at once, because 12>1012 > 10. So 286−140=146286 - 140 = 146.

Why it matters. Stars and bars with a ceiling is the same calculation as a discrete convolution, and the mirror symmetry halves the work whenever you compute a dice table by hand.

Question 7.19 ★★ QR, QT, Analyst, Risk • any • junior

Twelve people are split at random into three groups of four, and the groups have no labels. How many such splits exist? What is the probability that two particular people end up together?

Answer

Answer to Question 7.19.

There are 57755775 splits, and the chance that the two end up together is 3/113/11.

For the number of splits, start with 12!12! orderings, cut into three blocks of four, and divide out the orders inside each block and the orders of the blocks: 12!/(4!3 3!)=577512!/(4!^3\,3!) = 5775. Alternatively, choose the 3 companions of a fixed person, then the 3 companions of the first person left over: (113)(73)=165⋅35=5775\binom{11}{3}\binom{7}{3} = 165 \cdot 35 = 5775.

The second part needs no counting at all. Stand with the first person. Their group has 3 other places, and by symmetry the second person is equally likely to be in any of the other 11 places. So the chance is 3/113/11. Counting confirms it: (102)(73)=1575\binom{10}{2}\binom{7}{3} = 1575 of the 5775 splits have both together.

Classic wrong answer. Giving 1/31/3 because there are three groups. That would be right if each person chose a group independently, but your own group has only three places left, while the others have four each.

Follow-up. With labelled groups? The number of splits becomes 12!/4!3=34 65012!/4!^3 = 34\,650, six times as many. The probability stays the same.

Question 7.20 ★★ QR, QT, Trader • hedge fund, bank • junior

A knockout tournament has 64 players and a random draw, with every match a fair coin flip. What is the probability that two particular players meet? If instead the better player always wins, what is the probability that the second-best player reaches the final?

Answer

Answer to Question 7.20.

The two players meet with probability 1/321/32. The second-best player reaches the final with probability 32/6332/63.

For the first part, count matches rather than rounds. Exactly one player leaves in each match, so a 64-player tournament has 63 matches. There are (642)=2016\binom{64}{2} = 2016 pairs of players. By symmetry every pair is equally likely to be the pair in any given match, so each pair meets with probability 63/2016=1/3263/2016 = 1/32, and in general 2/n2/n.

For the second part, the second-best can lose only to the best. The two are in opposite halves of the draw exactly when the second-best reaches the final. Given the place of the best player, there are 63 other places, of which 32 lie in the other half. So the chance is 32/6332/63.

Classic wrong answer. Working through the rounds, with a factor for each round that both must survive. That can be done and takes much longer. Linearity with the matches gives the answer in one line.

Why it matters. This is why the runner-up in a knockout is a poor estimate of the second-best: it is right just over half the time.

Question 7.21 ★★ QR, QT, Trader, QD • any • junior

Put 6 points on a circle and draw every chord between them, in positions where no three chords pass through one interior point. How many regions does the disc split into? Why is the pattern 1, 2, 4, 8, 16 a trap? How many regions come from 10 points?

Answer

Answer to Question 7.21.

Six points give 31 regions, not 32, and 10 points give 256.

The formula is 1+(n2)+(n4)1 + \binom{n}{2} + \binom{n}{4}. Start with the disc, one region. Draw the chords one at a time. A new chord adds one region for itself, and one more for each chord it crosses, because each crossing cuts one more existing region in two. So the number of regions is 1+(chords)+(crossings)1 + (\text{chords}) + (\text{crossings}). There are (n2)\binom{n}{2} chords, and each set of 4 points gives exactly one crossing, the crossing of its two diagonals. So there are (n4)\binom{n}{4} crossings. For n=6n = 6: 1+15+15=311 + 15 + 15 = 31. For n=10n = 10: 1+45+210=2561 + 45 + 210 = 256.

The formula gives 1,2,4,8,161, 2, 4, 8, 16 for n=1,…,5n = 1, \dots, 5 only because ∑k(n−1k)\sum_k \binom{n-1}{k} matches it for small nn. A polynomial of degree 4 cannot keep up with 2n−12^{n-1}.

Classic wrong answer. Thirty-two, from the pattern. Interviewers ask this question to test whether a candidate will extrapolate from a few cases without a reason.

Follow-up. How can you check 31 with no formula? By Euler’s formula. With n+(n4)n + \binom{n}{4} vertices and n+(n2)+2(n4)n + \binom{n}{2} + 2\binom{n}{4} edges, the count of inner faces is E−V+1E - V + 1, which is the same result.

Question 7.22 ★★ QR, QT, QD, Dev • any • junior

In how many ways can you make 100 cents from coins worth 1, 5, 10, 25 and 50 cents, with order ignored and any number of each?

Answer

Answer to Question 7.22.

There are 292 ways.

Use dynamic programming on the coins, one denomination at a time. Let w(a)w(a) be the ways to make amount aa with the coins used so far, starting from w(0)=1w(0) = 1. For each coin cc, in turn, run aa upwards from cc and set w(a)←w(a)+w(a−c)w(a) \leftarrow w(a) + w(a - c). Going upwards lets a coin be reused, and going coin by coin counts each combination once only, regardless of order. This is the same as reading a coefficient in the generating function ∏c1/(1−xc)\prod_c 1/(1 - x^c).

By hand, work over the numbers of large coins. With no 50 and no 25, for instance, choosing dd dimes leaves 21−2d21 - 2d choices of nickels, and pennies fill the rest, which gives 121 ways for that case. Adding all the cases gives 292. An exhaustive loop over 50s, 25s, 10s and 5s, with pennies making up the rest, gives the same number.

Classic wrong answer. Looping amounts first and coins inside. That counts 1+51 + 5 and 5+15 + 1 as different, which counts orderings instead of combinations.

Follow-up. And the number of ways counting order? Swap the two loops. It grows enormous, because most of the sequences use many pennies.

Question 7.23 ★★ QR, QT, Trader • any • junior

How many solutions in whole numbers does x+y+z=30x + y + z = 30 have when each of x,y,zx, y, z must lie between 0 and 15?

Answer

Answer to Question 7.23.

There are 136 solutions.

With no ceiling, stars and bars gives (322)=496\binom{32}{2} = 496. Now subtract the solutions in which a variable exceeds 15. If x≥16x \ge 16, put x′=x−16x' = x - 16. Then x′+y+z=14x' + y + z = 14, which has (162)=120\binom{16}{2} = 120 solutions. There are three such cases, and two variables cannot both be at least 16, since their sum would exceed 30. So inclusion-exclusion stops there: 496−360=136496 - 360 = 136.

A check by geometry: the solutions form a triangular slice of a cube, and with a ceiling of half the total, the slice is the central triangle formed by the three midpoints. It has about a quarter of the unrestricted triangle’s area, and 136/496≈0.27136/496 \approx 0.27, a little more because of the boundary points.

Why it matters. Ceilings appear whenever capacity limits a split. This is the standard way to treat them, and it stops after one or two terms when the ceiling is large.

Question 7.24 ★★ QR, QT, Trader • hedge fund, market maker • junior

You shuffle a 52-card deck. What is the probability that all four aces come before any king? What if you also require all four queens to come after the kings?

Answer

Answer to Question 7.24.

The first is 1/701/70, and the second is 1/34 6501/34\,650.

Ignore all the other cards. Only the relative order of the 8 aces and kings matters, and every way of placing those is equally likely. Of the (84)=70\binom{8}{4} = 70 patterns of A and K, exactly one has all the A’s first. The other 44 cards are irrelevant.

For twelve cards with the order aces, kings, queens, look at the patterns of three letters: there are 12!/(4!)3=34 65012!/(4!)^3 = 34\,650 of them, and one is right.

Classic wrong answer. Multiplying conditional chances for each ace, such as 452\tfrac{4}{52} for the first, then trying to track the deck. Removing irrelevant cards is the whole point.

Why it matters. This kind of reduction, where only the relative order of a few events matters, applies to any question of which event happens first among exchangeable times, such as which order fills first in a random arrival sequence.

Question 7.25 ★★ QR, QT, Trader, DS • any • junior

You and I each flip a fair coin 10 times. What is the probability that we get the same number of heads? Find a closed form with one binomial coefficient.

Answer

Answer to Question 7.25.

The probability is (2010)/410=184 756/1 048 576≈0.176\binom{20}{10}/4^{10} = 184\,756/1\,048\,576 \approx 0.176.

The direct sum is ∑k(10k)2/410\sum_k \binom{10}{k}^2 / 4^{10}. The neat way sees the equal-heads event as a statement about 20 flips. Change the meaning of my flips by swapping heads with tails, which leaves them fair. Then “your heads equals my heads” becomes “your heads plus my new heads equals 10”, because my new heads is 1010 minus my old heads. This is the event of exactly 10 heads in 20 fair flips, and its probability is (2010)/220\binom{20}{10}/2^{20}.

The same argument proves the identity ∑k(nk)2=(2nn)\sum_k \binom{n}{k}^2 = \binom{2n}{n}, and for large nn the probability is about 1/πn1/\sqrt{\pi n}, here 0.1780.178.

Classic wrong answer. One over 11, since there are 11 possible counts. The counts are not equally likely, and the central ones carry most of the mass.

Why it matters. The chance of an exact tie after nn rounds falls only with the square root of nn. Ties in a large sample are far more common than intuition suggests.

Question 7.26 ★★ QR, QT, QD, DS • any • junior

You form two random subsets AA and BB of a 10-element set, with each element put into each subset independently with probability 1/21/2. How likely is it that AA is contained in BB? That AA and BB are disjoint? That they are equal?

Answer

Answer to Question 7.26.

Containment has probability (3/4)10≈0.056(3/4)^{10} \approx 0.056, disjointness has the same probability, and equality has probability (1/2)10=1/1024(1/2)^{10} = 1/1024.

Each element acts independently, and each has four cases: in AA only, in BB only, in both, or in neither. For A⊆BA \subseteq B, only “in AA only” is forbidden, so each element contributes 3/43/4. So there are 3103^{10} good pairs among 4104^{10}.

For disjointness, only “in both” is forbidden, and again each element contributes 3/43/4. Complementing BB turns one into the other, which is why they are equal. For equality, an element must be either in both or in neither, which has probability 1/21/2.

Classic wrong answer. Conditioning on the size of AA, and summing over that size. It does give the same answer, by the binomial theorem, but the element-by-element view avoids any sum.

Follow-up. What about A⊆B⊆CA \subseteq B \subseteq C? Each element has 8 cases, of which 4 are allowed: (1/2)10(1/2)^{10}.

Question 7.27 ★★ QR, QT, Trader, QD • any • junior

You pick 3 chairs from 20 in a row so that no two are adjacent. How many choices are there? How many if the 20 chairs stand in a circle, with the last next to the first?

Answer

Answer to Question 7.27.

In a row there are 816 choices, and in a circle there are 800.

In a row, use a gap argument. Remove one chair from between each neighbouring pair of chosen chairs. Choosing 3 of 20 with no two adjacent then matches choosing 3 of 20−2=1820 - 2 = 18 chairs, with no condition. So (183)=816\binom{18}{3} = 816.

In a circle, split on whether chair 1 is chosen. If it is, its two neighbours are out, and you need 2 non-adjacent chairs from the other 17 in a row: (162)=120\binom{16}{2} = 120. If it is not, you need 3 non-adjacent from 19 in a row: (173)=680\binom{17}{3} = 680. The total is 800. The general formula is nn−k(n−kk)\frac{n}{n-k}\binom{n-k}{k}.

The row and circle differ by those selections containing both end chairs, which are adjacent only on the circle. Fixing both, the third chair must come from chairs 3 to 18, which gives 16, and 816−16=800816 - 16 = 800 exactly.

Why it matters. The difference between a row and a ring is a recurring trap. A clean way to check a circular answer is to count what closing the row into a ring removes.

Question 7.28 ★★★ QR, QT, Trader • hedge fund, market maker • junior, experienced

Five couples sit in a row of 10 chairs at random. What is the probability that no couple sits together? Give the exact count.

Answer

Answer to Question 7.28.

The count is 1 263 3601\,263\,360 out of 10!=3 628 80010! = 3\,628\,800, or about 0.3480.348.

Use inclusion-exclusion over the set of couples that sit together. Fix kk couples and glue each into a block. There are then 10−k10 - k objects, which can be arranged in (10−k)!(10 - k)! ways, and each block has 2 internal orders, so the term is (5k)2k(10−k)!\binom{5}{k} 2^k (10 - k)!. So

∑k=05(−1)k(5k)2k(10−k)!=3 628 800−3 628 800+1 612 800−403 200+57 600−3840.\sum_{k=0}^{5} (-1)^k \binom{5}{k} 2^k (10 - k)! = 3\,628\,800 - 3\,628\,800 + 1\,612\,800 - 403\,200 + 57\,600 - 3840.

The first two terms cancel exactly, which is a small surprise, and the sum is 1 263 3601\,263\,360. The same formula gives 8 and 240 for two and three couples, which you can check by listing.

An approximation is a useful check. The expected number of couples together is 5⋅2/10=15 \cdot 2/10 = 1, and if that number were Poisson with mean 1, the answer would be e−1≈0.368e^{-1} \approx 0.368. The right answer is a bit lower, because the events are not independent, and it approaches 1/e1/e for many couples.

Classic wrong answer. Multiplying (1−1/5)5≈0.328(1 - 1/5)^5 \approx 0.328 as if the events were independent. Not bad as an estimate, but it is not exact, and an exact count was asked for.

Follow-up. How does a round table change it? Glued blocks arranged on a circle give (9−k)!(9 - k)! arrangements with the same signs, and the count differs. Remember the factor for rotations.

Question 7.29 ★★★ QR, QT • hedge fund, market maker • experienced

How many subsets of {1,2,…,10}\{1, 2, \dots, 10\}, counting the empty set, have a sum divisible by 5? Do it without listing subsets.

Answer

Answer to Question 7.29.

There are 208 such subsets.

Use the roots-of-unity filter. Let ω=e2πi/5\omega = e^{2\pi i/5}, and consider f(x)=∏k=110(1+xk)f(x) = \prod_{k=1}^{10}(1 + x^k). The coefficient of xsx^s counts subsets with sum ss. Averaging ff over the five fifth roots of unity keeps exactly the terms where ss is divisible by 5:

N=15∑j=04f(ωj).N = \frac15 \sum_{j=0}^{4} f(\omega^j).

At j=0j = 0 you have f(1)=210=1024f(1) = 2^{10} = 1024. For j≠0j \ne 0, the powers ωjk\omega^{jk} run twice through all fifth roots of unity as kk goes from 1 to 10, so f(ωj)=[∏r=04(1+ωr)]2f(\omega^j) = \bigl[\prod_{r=0}^{4}(1 + \omega^r)\bigr]^2. Since ∏r(x−ωr)=x5−1\prod_r (x - \omega^r) = x^5 - 1, putting x=−1x = -1 gives ∏r(1+ωr)=2\prod_r (1 + \omega^r) = 2. So each of the four terms is 22=42^2 = 4, and

N=1024+4⋅45=208.N = \frac{1024 + 4 \cdot 4}{5} = 208.

The others share the remainder evenly, at 204 for each non-zero residue. So the distribution is almost flat, and the small excess for residue 0 is exactly what the filter sees.

Classic wrong answer. Answering 1024/51024/5, which is not even a whole number, or assuming perfect uniformity. Each block of {1,…,5}\{1, \dots, 5\} holds a multiple of 5, so the residues are not perfectly balanced.

Follow-up. And for subsets of {1,…,5}\{1, \dots, 5\}? The powers run once through the roots, so (32+4⋅2)/5=8(32 + 4 \cdot 2)/5 = 8. Listing them confirms it.

Question 7.30 ★★★ QR, QT, QD • any • junior, experienced

Three red and three green beads are placed evenly on a ring. How many different rings are there if rotations count as the same? How many if a ring can also be flipped over?

Answer

Answer to Question 7.30.

There are 4 rings under rotation, and 3 if flipping is also allowed.

Use Burnside’s lemma: the number of distinct rings is the average, over the symmetries, of the number of bead patterns that each symmetry leaves unchanged. There are (63)=20\binom{6}{3} = 20 patterns.

Under rotation, the identity keeps all 20. A rotation by one or five steps moves all beads in a single cycle, so it would need all beads the same: 0 patterns. A rotation by two or four has two cycles of length 3, so one must be red and the other green: 2 patterns each. A rotation by three has three cycles of length 2, and red would have to be even: 0. The average is (20+2+2)/6=4(20 + 2 + 2)/6 = 4. They are RRRGGG, RRGRGG, RRGGRG and RGRGRG.

Adding flips, three reflections through opposite beads each keep 4 patterns, because the two beads on the axis must differ and one of the other two pairs is red. The three through gaps keep none, because pairs make red even. The average is (24+12)/12=3(24 + 12)/12 = 3. The two mirror images RRGRGG and RRGGRG become one.

Classic wrong answer. Dividing 2020 by the 6 rotations, which gives 10/310/3. A pattern with symmetry has a smaller orbit, so simple division is wrong, and the lemma exists to correct it.

Question 7.31 ★★★ QR, QT, QD • any • junior, experienced

You paint each face of a cube one of two colours. How many different cubes can you make, if two cubes are the same when one can be rotated to look like the other? How many with three colours?

Answer

Answer to Question 7.31.

There are 10 cubes with two colours, and 57 with three colours.

Use Burnside’s lemma on the 24 rotations of the cube. A rotation fixes a colouring exactly when each cycle of faces it creates is one colour, so with kk colours a rotation with cc cycles fixes kck^c colourings. The rotations split by cycle count:

  • the identity has 6 cycles (one rotation);
  • a half-turn about the axis through two opposite faces has 4 cycles (three rotations);
  • a quarter-turn about that axis has 3 cycles (six rotations);
  • a half-turn about the axis through two opposite edges has 3 cycles (six rotations);
  • a rotation about the axis through two opposite corners has 2 cycles (eight rotations).

This totals 1+3+6+6+8=241 + 3 + 6 + 6 + 8 = 24, and the number of cubes is

k6+3k4+12k3+8k224,\frac{k^6 + 3k^4 + 12k^3 + 8k^2}{24},

which gives 10 for k=2k = 2 and 57 for k=3k = 3. With k=1k = 1 it gives 1, a useful check on the group count.

For k=2k = 2 you can list by number of faces of colour A, from 0 to 6: 1,1,2,2,2,1,11, 1, 2, 2, 2, 1, 1. These add up to 10, confirming the formula.

Classic wrong answer. 26/242^6/24, which is not even a whole number. Colourings with symmetry have smaller orbits.

Follow-up. And colourings using all six colours once each? No rotation except the identity fixes one, so 6!/24=306!/24 = 30.

Question 7.32 ★★★ QR, QT, Trader • any • junior, experienced

You choose 3 of the 12 corners of a regular 12-sided polygon at random. How likely is it that the triangle has a right angle? That it strictly contains the centre of the polygon?

Answer

Answer to Question 7.32.

A right angle has probability 60/220=3/1160/220 = 3/11. Strictly containing the centre has probability 40/220=2/1140/220 = 2/11.

There are (123)=220\binom{12}{3} = 220 triangles. By the angle in a semicircle, a triangle with vertices on a circle has a right angle exactly when one side is a diameter. There are 6 diameters and 10 choices of third corner, which gives 60.

Go round the polygon and write the three arcs between consecutive corners as whole numbers adding up to 12. A triangle strictly contains the centre exactly when each arc is below 6. An arc of exactly 6 is the right-angled case, and an arc above 6 leaves the centre outside the triangle (an obtuse triangle).

Count the obtuse ones. Fix the corner at which the largest arc ends, so that the other two corners lie within the next 5 steps: there are 12 choices for that corner and (52)=10\binom{5}{2} = 10 choices for the other two. So there are 120 obtuse triangles, and 220−60−120=40220 - 60 - 120 = 40 acute.

Classic wrong answer. Using 1/41/4, which is the answer for three uniform points on a circle. A finite polygon has right-angled triangles that take up probability, so the acute share is lower. As the number of corners grows, the answer does approach 1/41/4.

Follow-up. Three uniform points: why 1/41/4? The arcs are a uniform point on a simplex, and the region where all arcs are below a half is the central triangle, a quarter of the simplex.

Question 7.33 ★★★ QR, QT, QD • hedge fund, market maker • junior, experienced

Show that any 10 different numbers chosen from 1 to 100 contain two disjoint non-empty groups with the same sum. Why does your argument not work for 7 numbers, and can you give 7 numbers for which no two different groups have equal sums?

Answer

Answer to Question 7.33.

Use the pigeonhole principle, comparing the number of subsets with the number of possible sums. For 7 numbers the count of subsets is too small to force a match, and the powers 1, 2, 4, 8, 16, 32, 64 have all their 127 subset sums different.

Any 10 numbers from 1 to 100 have 210−1=10232^{10} - 1 = 1023 non-empty subsets. Each has a sum between 1 and at most 91+92+⋯+100=95591 + 92 + \dots + 100 = 955. There are more subsets than sums, so two different subsets have the same sum.

Those two may overlap. Remove their common elements from both: the sums stay equal to each other, and they stay different sets. Neither is left empty, because the numbers are positive, and if one set were emptied, the other would have to have sum zero. So you have two disjoint non-empty groups with the same sum.

For 7 numbers there are only 127 subsets, and sums can reach up to 679, so the pigeonhole argument gives nothing. The powers of two are a counterexample, because binary digits are unique. So the statement itself is false at 7, not just the proof.

Classic wrong answer. Trying to construct the two groups. The argument proves they exist without showing which they are, and that is the point of the question.

Why it matters. Pigeonhole arguments give very quick bounds, and the same comparison of counts gives a lower limit on the number of bits needed by a hash.

Question 7.34 ★★★ QR, QT, Trader, Risk • any • junior, experienced

A walk starts at 0 and takes 10 steps, each +1+1 or −1-1 with equal probability. What is the probability that it reaches +4+4 at some point? Count it without listing paths.

Answer

Answer to Question 7.34.

The probability is 232/1024=29/128≈0.227232/1024 = 29/128 \approx 0.227.

Use the reflection principle. A path that reaches +4+4 and ends below 4 can be flipped after its first touch of 4, and that gives a path ending above 4. This is a bijection. So

P(max⁡≥4)=P(S10≥4)+P(S10>4).P(\max \ge 4) = P(S_{10} \ge 4) + P(S_{10} > 4).

Paths ending at or above 4 must have 7 or more up steps: (107)+(108)+(109)+(1010)=120+45+10+1=176\binom{10}{7} + \binom{10}{8} + \binom{10}{9} + \binom{10}{10} = 120 + 45 + 10 + 1 = 176. Paths ending above 4 must have 8 or more: 56. The total is 176+56=232176 + 56 = 232 out of 2102^{10}.

Classic wrong answer. Doubling P(S10≥4)P(S_{10} \ge 4), to get 352/1024352/1024. The continuous-time formula does give a factor of two, but here the paths that end exactly on 4 must be counted once, not twice. That makes a big difference over only 10 steps.

Follow-up. What does the continuous limit say? Brownian motion over time TT reaches a level aa with probability 2P(WT>a)2P(W_T > a), where exact hits have no mass. The difference falls with the number of steps.

Why it matters. This is the reflection used for barrier options: the chance of touching a level in a period is about twice the chance of ending beyond it. Near the level on a coarse grid, the discrete correction matters.

Question 7.35 ★★★ QR, QT, Trader, QD • any • junior, experienced

A six-digit ticket, from 000000 to 999999, is lucky if the sum of its first three digits equals the sum of its last three. How many lucky tickets are there? Find a way to count them from a single coefficient.

Answer

Answer to Question 7.35.

There are 55 25255\,252 lucky tickets.

The trick is a bijection. Replace each of the last three digits dd by 9−d9 - d. A ticket is lucky when a+b+c=d+e+fa + b + c = d + e + f. After the replacement, d′+e′+f′=27−(d+e+f)d' + e' + f' = 27 - (d + e + f), so the condition becomes a+b+c+d′+e′+f′=27a + b + c + d' + e' + f' = 27. So you are counting six-digit strings whose digits add up to 27, which is a single coefficient: that of x27x^{27} in (1+x+⋯+x9)6(1 + x + \dots + x^9)^6.

Find this using stars and bars with inclusion-exclusion. With no ceiling, the number of solutions is (325)=201 376\binom{32}{5} = 201\,376. Subtract 6 times the number with one digit at least 10, which is (225)=26 334\binom{22}{5} = 26\,334, and add back 15 times the number with two such digits, (125)=792\binom{12}{5} = 792. Three digits at least 10 would need 30, so you stop there:

201 376−158 004+11 880=55 252.201\,376 - 158\,004 + 11\,880 = 55\,252.

Check by the direct sum of squares: for each value ss from 0 to 27, the number of three-digit strings with sum ss is squared and these are added up, which gives the same total. The peak term is 75275^2 at s=13s = 13.

Classic wrong answer. Assuming that about 1 in 28 tickets is lucky, which is 35 714. Sums near the centre are much more likely, so a match is more likely than that: the true rate is about 1 in 18.

Question 7.36 ★★★ QR, QT, QD • any • junior, experienced

In how many ways can you fill a 5×55 \times 5 table with zeros and ones so that every row and every column has an even sum?

Answer

Answer to Question 7.36.

There are 216=65 5362^{16} = 65\,536 such tables.

Think of free choices. Fill in the top-left 4×44 \times 4 block in any way: that is 2162^{16} choices. Each of the first four rows then has its last entry forced so that the row has even sum, and each of the first four columns has its last entry forced in the same way. Only the bottom-right corner remains.

The corner must fix both the last row and the last column, and these two demands agree. The sum of the last column’s top four entries and the sum of the last row’s first four entries are each the parity of the sum of the 4×44 \times 4 block: each is obtained by adding up the rows, or the columns, of the block. So the corner exists and is unique, whichever block you chose.

In general the count for n×nn \times n is 2(n−1)22^{(n-1)^2}. Enumeration gives 2, 16 and 512 for n=2,3,4n = 2, 3, 4, as it should.

Classic wrong answer. Counting equations and unknowns naively: 25 unknowns less 10 constraints leaves 2152^{15}. The 10 equations are not independent, because the sum of all rows and the sum of all columns are the same sum, so one equation is redundant.

Why it matters. Parity grids are the idea behind RAID storage and simple error-correcting codes. The redundant equation is what lets you find a failed entry.

Question 7.37 ★★★ QR, QT, QD • hedge fund, market maker • junior, experienced

A permutation of 1,…,n1, \dots, n has an ascent wherever an entry is followed immediately by a larger one. How many permutations of 1,…,n1, \dots, n have exactly one ascent? Give a formula and its value for n=5n = 5.

Answer

Answer to Question 7.37.

The count is 2n−n−12^n - n - 1, which is 26 for n=5n = 5.

A permutation with exactly one ascent is two descending runs placed one after the other. Each is decided by its set of entries, because a descending run has only one order. So choose a subset SS for the first run: there are 2n2^n subsets, and the other entries form the second run.

Each permutation with one ascent arises from exactly one subset. But some subsets do not make an ascent. If the first run’s last entry is larger than the second run’s first entry, the whole thing descends, and there is no ascent. That happens exactly when SS is the set of the top kk values, for k=0,1,…,nk = 0, 1, \dots, n: that is n+1n + 1 subsets, each giving the single fully descending permutation. So the count is 2n−(n+1)2^n - (n + 1).

Enumeration agrees: n=3n = 3 gives 4, namely 132, 213, 231 and 312, and n=4n = 4 gives 11, n=5n = 5 gives 26, n=6n = 6 gives 57.

Classic wrong answer. Choosing where the ascent goes, with n−1n - 1 positions, and a subset of fixed size. That gives the right total only if you subtract the subsets at each size that make no ascent, and it is a slower route to the same count.

Follow-up. What are these numbers called? Eulerian numbers. They count permutations by their number of ascents, and they appear when you sum powers of integers.

Question 7.38 ★★★★ QR, QT • hedge fund, market maker • experienced

Find a pair of six-sided dice, with positive whole numbers on the faces and not both standard, whose sum has the same distribution as the sum of two ordinary dice. Show that it is the only pair.

Answer

Answer to Question 7.38.

The pair is {1,2,2,3,3,4}\{1, 2, 2, 3, 3, 4\} and {1,3,4,5,6,8}\{1, 3, 4, 5, 6, 8\}, known as Sicherman dice, and it is the only other pair.

Use generating functions. A die is a polynomial D(x)=∑xfaceD(x) = \sum x^{\text{face}}, and the sum of two dice has the product as its generating function. The target is

(x+x2+⋯+x6)2=x2(1+x)2(1+x+x2)2(1−x+x2)2,(x + x^2 + \dots + x^6)^2 = x^2 (1 + x)^2 (1 + x + x^2)^2 (1 - x + x^2)^2,

and these factors are irreducible over the integers. Polynomial factorisation is unique, so each die DD is a product of some of these. Two conditions apply to each die. First, it must have D(0)=0D(0) = 0, because the faces are positive, so it takes one factor of xx. Second, it must have D(1)=6D(1) = 6, because it has six faces. At x=1x = 1, the factors take the values 22, 33 and 11. To get 6, each die must take exactly one (1+x)(1 + x) and one (1+x+x2)(1 + x + x^2).

Only the (1−x+x2)(1 - x + x^2) factors, whose value at 1 is 1, can move. Sharing them 1+11 + 1 gives standard dice. Sharing them 2+02 + 0 gives

x(1+x)(1+x+x2)=x+2x2+2x3+x4x(1 + x)(1 + x + x^2) = x + 2x^2 + 2x^3 + x^4

and x(1+x)(1+x+x2)(1−x+x2)2=x+x3+x4+x5+x6+x8x(1 + x)(1 + x + x^2)(1 - x + x^2)^2 = x + x^3 + x^4 + x^5 + x^6 + x^8.

A computer search of all face sets confirms it: there are exactly these two solutions.

Classic wrong answer. Searching by hand with “the two dice must sum to 42 together”. It is a true necessary condition, but it does not lead you to the pair, and it proves nothing about uniqueness.

Follow-up. Three dice? The same factorisation has more possibilities, and there are non-standard triples, also found by moving the (1−x+x2)(1 - x + x^2) factors.

Question 7.39 ★★★★ QR, QT • hedge fund, market maker • experienced

Five couples sit around a round table, alternating men and women, so that nobody sits next to their partner. Rotations count as the same seating. How many seatings are there? What is the probability that a random alternating seating qualifies?

Answer

Answer to Question 7.39.

There are 312 seatings, and the chance that a random alternating seating qualifies is 13/120≈0.10813/120 \approx 0.108.

This is the ménage problem. Fix one man to remove the rotations: the other men can be placed in 4!=244! = 24 ways. Between men there are five places for the women, and each woman is barred from two adjacent places: the ones beside the matching partner. So you need the number of assignments of 5 women to 5 places, with these barred positions, and this number does not depend on how the men sit.

The bars form a single ring of 10 cells: woman, place, woman, place, and so on. Choosing kk violations is choosing kk cells of the ring with no two neighbouring, because a woman or a place cannot be used twice. There are 2n2n−k(2n−kk)\frac{2n}{2n - k}\binom{2n - k}{k} such choices, and the n−kn - k others are placed freely, so by inclusion-exclusion,

Mn=∑k=0n(−1)k2n2n−k(2n−kk)(n−k)!,M5=13.M_n = \sum_{k=0}^{n} (-1)^k \frac{2n}{2n - k}\binom{2n - k}{k} (n - k)!, \qquad M_5 = 13.

The total is 4!⋅13=3124! \cdot 13 = 312, out of 4!⋅5!=28804! \cdot 5! = 2880 alternating seatings. Checking all 2 880 by machine gives the same count, and the formula also gives M6=80M_6 = 80.

Classic wrong answer. Treating each woman as independently having a 3/53/5 chance of a valid place, which gives (3/5)5≈0.078(3/5)^5 \approx 0.078. The choices compete for places, and they are far from independent.

Follow-up. For large nn? Each woman has 2 barred places out of nn, so the expected number of violations is 2, and the fraction tends to e−2≈0.135e^{-2} \approx 0.135, which is a fair check here.

Question 7.40 ★★★★ QR, QT, Trader • hedge fund, market maker, bank • experienced

A hundred prisoners are numbered 1 to 100. A room holds 100 boxes, also numbered, with the prisoners’ numbers placed in them in a random order, one in each. One at a time, each prisoner enters and may open 50 boxes, then leaves everything as it was, and may not communicate with the others afterwards. All are freed if every prisoner opens the box holding their own number. They may agree on a plan beforehand. What plan is best, and what is its chance of success, roughly?

Answer

Answer to Question 7.40.

Each prisoner should start at the box with their own number and follow the numbers inside. The chance of success is 1−∑k=511001/k≈0.3121 - \sum_{k=51}^{100} 1/k \approx 0.312, compared with 2−1002^{-100} for random guessing.

Each box holds a number that is the label of another box, so the boxes form a permutation. If a prisoner opens box ii, finds the number jj, then opens box jj and so on, the prisoner walks along the cycle that contains ii. That cycle ends at the box holding ii, which is exactly what the prisoner wants. So the prisoner succeeds if and only if the cycle is at most 50 long. All succeed if and only if the permutation has no cycle longer than 50.

A permutation of 100 has at most one cycle longer than 50. The number of permutations with a cycle of length exactly k>50k > 50 is found by choosing its elements, (100k)\binom{100}{k}, arranging them in a cycle, (k−1)!(k - 1)!, and arranging the rest, (100−k)!(100 - k)!. This is 100!/k100!/k. So the chance of a long cycle is ∑k=511001/k≈ln⁡2\sum_{k=51}^{100} 1/k \approx \ln 2, and success has probability about 1−ln⁡2≈0.3071 - \ln 2 \approx 0.307.

The strategy works because success is highly correlated: all prisoners succeed or fail together, depending on one property of the permutation.

Classic wrong answer. “Each has 1/21/2, so it is 2−1002^{-100} whatever they do, because nobody can pass information.” The individual chance really is 1/21/2. What the plan changes is the correlation between them, and independence is what is being given up.

Why it matters. It is the best example of a pattern that matters for risk: you cannot change a position’s marginal behaviour, but correlation decides what happens to all the positions together.