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

Interviews I: Maths, Probability and Speed

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

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

16Logic Riddles

Finding the one idea that makes a puzzle short. A weighing gives three outcomes, a bit encodes a yes or a no, a colouring or a parity is an invariant that no move can change, and what other people know is information. In an interview, say the idea first, then check it on a small case.

Question 16.1 ★ QR, QT, Trader, Analyst, QD • any • junior

You have 8 identical-looking balls, one of them slightly heavier, and a balance with two pans. How many weighings do you need to find the heavy ball for certain, and how? How many balls could you handle with 4 weighings?

Answer

Answer to Question 16.1.

Two weighings for 8 balls, and 81 balls with 4 weighings.

A balance has three outcomes: left heavy, right heavy, or level. So kk weighings separate at most 3k3^k cases. Put 3 against 3. If one side is heavy, the ball is among those 3. If level, it is among the other 2. Then one more weighing finds it among 3, by putting 1 against 1.

Classic wrong answer. Halving each time, as if the balance had only two outcomes: 4 against 4, then 2 against 2, then 1 against 1. That takes 3 weighings, and it never uses the level outcome.

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

You have two ropes and a lighter. Each rope takes exactly 60 minutes to burn from one end to the other, but it burns unevenly, so half of a rope need not take 30 minutes. How do you measure exactly 45 minutes?

Answer

Answer to Question 16.2.

Light rope A at both ends and rope B at one end. When A burns out, after 30 minutes, light the other end of B. It burns out 15 minutes later, for 45 in all.

Burning from both ends halves the time, however uneven the rope is, because the two flames together consume the whole 60 minutes of burning. When A is gone, rope B has 30 minutes of burning left, and the second flame halves that.

Classic wrong answer. Cutting a rope in half or in a quarter. The burn rate is uneven, so length says nothing about time. Only the time totals can be used.

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

You have a 4-minute sand timer and a 7-minute sand timer, and you can turn either over at the moment when one of them runs out. How do you measure exactly 9 minutes, starting both at time 0?

Answer

Answer to Question 16.3.

Start both. At 4, turn the 4-minute timer. At 7, turn the 7-minute timer. At 8, the 4-minute timer runs out, and the 7-minute timer has run for 1 minute, so turn it over and it runs for that 1 minute back. That ends at 9.

The trick is to use the sand that has already fallen. A timer that has run for tt minutes, once turned, measures exactly tt minutes. So you need to find a moment where such a timer has the amount you need: here 1 minute after the 8-minute mark.

Classic wrong answer. Trying to combine only multiples, as with 4a+7b4a + 7b, which does not include 9. You can only get 9 by using a turn at a moment when a timer is part of the way through.

Question 16.4 ★ QR, QT, Trader, Analyst, QD • any • junior

There are 10 bags of coins. In nine of them each coin weighs 10 grams, and in one of them each coin weighs 11 grams. You have an accurate scale that gives a number, and you may use it once. How do you find the bag?

Answer

Answer to Question 16.4.

Take 1 coin from bag 1, 2 from bag 2, and so on up to 10 from bag 10. That is 55 coins, which would weigh 550 grams if all were genuine. The excess in grams is the number of the heavy bag.

One reading of a scale can carry many values, so you make each bag contribute a different amount. The excess is kk when bag kk is the fake one, and this is different for each of the ten cases.

Classic wrong answer. Weighing one bag at a time, which needs up to nine uses of the scale. A scale is a number, not a yes or a no.

Question 16.5 ★ QR, QT, Analyst • any • junior

You must take exactly one pill of type A and one of type B each day. The pills look identical, and they are expensive. Today you tipped out one A and then, by accident, two B into your hand, and you cannot tell the three apart. How do you get today’s correct dose without wasting a pill?

Answer

Answer to Question 16.5.

Take one more A from its bottle, so that you hold 2 A and 2 B. Cut each of the four pills in half, and put one half of each into today’s pile, and the other half into tomorrow’s.

You cannot tell the pills apart, so you cannot select by type, but you can make the selection the same for every pill. Today’s four halves are half of 2 A and half of 2 B, which is exactly one A and one B. Tomorrow’s four halves are the same dose. No pill is wasted.

Classic wrong answer. Throwing the pills away and starting afresh, which fails the question, or taking any two of the three, which risks a wrong dose.

Question 16.6 ★ QR, QT, Analyst, QD • any • junior

A gold chain has 7 links in a row. You must pay a worker one link’s worth of gold at the end of each of 7 days, and you may take back earlier pieces as change. Cutting a link frees it as a single piece and splits the chain on either side of it. What is the fewest links you must cut, and which? With 2 cuts, what is the longest chain that you could pay out in this way, one link a day?

Answer

Answer to Question 16.6.

One cut is enough, at the third link (or, by symmetry, the fifth), which leaves pieces of 1, 2 and 4 links. With 2 cuts, a chain of 23 links works.

On day dd the worker must hold exactly dd links, so the pieces must be able to make every total from 1 to 7, using each piece at most once. Pieces of 1, 2 and 4 do this, as in binary. So on day 2 you take back the 1 and hand over the 2.

With 2 cuts you get two single links, which reach 2. The next piece may then be 3, reaching 5, the next 6, reaching 11, and the last 12, reaching 23. So 1+1+3+6+12=231 + 1 + 3 + 6 + 12 = 23. Trying every pair of cuts confirms that no longer chain works.

Classic wrong answer. Three cuts, at links 2, 4 and 6, which leave seven single links to hand over one a day. This ignores change, which is the point of the puzzle.

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

Two opposite corner squares are removed from an 8 by 8 chessboard. Can the remaining 62 squares be covered by 31 dominoes, each covering two neighbouring squares? What if you remove two squares of opposite colours instead, anywhere on the board?

Answer

Answer to Question 16.7.

No for the opposite corners. Yes for any two squares of opposite colours.

Colour the board in the usual way. A domino covers one black and one white square. Opposite corners have the same colour, so the rest has 30 of one colour and 32 of the other, and dominoes cannot cover that.

For two squares of opposite colours, there is a nice proof. Draw a closed path through all 64 squares, moving between neighbours, for example a comb shape. Removing two squares of opposite colours breaks the path into two pieces, each with an even number of squares, because colours alternate along the path. Each piece is covered by dominoes laid along it. An exhaustive search on a 4 by 4 board agrees.

Classic wrong answer. Trying to place the dominoes one by one and getting stuck, and saying that it seems to be impossible. That proves nothing. A colour count does it in one line.

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

Two people will each get a black or white hat at random. Each sees the other’s hat only, and they guess their own hat colour at the same moment, with no signal. They may agree on a plan first. They win if at least one guess is right. Find a plan that always wins.

Answer

Answer to Question 16.8.

One always says the colour they see on the other. The other always says the opposite of what they see. Exactly one of them is right.

If the hats match, the first is right. If the hats differ, the second is right. These are the only two cases, so one of them always wins. Each person is right half of the time, as they must be, because they know nothing about their own hat. The plan does not change that. It arranges that the right guesses never coincide.

Classic wrong answer. Saying this cannot be done, since each guess is a coin flip. It is true for each guess alone. A plan can correlate the guesses.

Question 16.9 ★ QR, QT, Analyst • any • junior

Three switches outside a closed room control three ordinary filament bulbs inside. You may set the switches as you wish, then enter the room once, after which you cannot touch them. How do you tell which switch controls which bulb?

Answer

Answer to Question 16.9.

Turn switch 1 on for ten minutes, turn it off, then turn switch 2 on, and enter. The lit bulb is switch 2, the warm unlit bulb is switch 1, and the cold unlit bulb is switch 3.

One look at an on or off state gives only two values, which is not enough for three switches. A filament bulb has a further state, its temperature. You need a third signal, and heat is one you can create in advance.

Classic wrong answer. Saying it cannot be done, because there is one entry and only two states. Ask what else can differ about a bulb. An interviewer may want to hear you question the model, not only the arithmetic.

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

Three boxes are labelled “apples”, “oranges” and “mixed”, and you are told that every label is wrong. You may take one fruit from one box of your choice without looking inside. Which box do you choose, and how do you then relabel all three?

Answer

Answer to Question 16.10.

Take a fruit from the box labelled “mixed”. It really holds only the fruit that you draw. If you draw an apple, that box is apples, the box labelled “oranges” cannot be oranges and it cannot be apples, so it is mixed, and the box labelled “apples” is oranges.

All labels are wrong, so only two arrangements are possible. The box labelled “mixed” holds pure fruit in both of them, so one draw from it tells you which arrangement you have. A draw from the box labelled “apples” may show an orange in both arrangements, and in that case it tells you nothing.

Classic wrong answer. Choosing a box at random. A fruit from a box that may be mixed does not settle what the box contains.

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

Four people must cross a bridge at night with one torch. At most two can cross at a time, and any crossing needs the torch, which must be walked back. They take 1, 2, 5 and 10 minutes to cross, and a pair moves at the slower one’s pace. What is the shortest total time, and what is the plan?

Answer

Answer to Question 16.11.

The shortest time is 17 minutes. Persons 1 and 2 cross (2 minutes), 1 returns (1), persons 5 and 10 cross (10), 2 returns (2), and 1 and 2 cross (2).

The natural plan is to use the fastest person to escort everyone, which takes 10+1+5+1+2=1910 + 1 + 5 + 1 + 2 = 19. The better plan sends the two slowest together, so that the 5 costs nothing extra, at the price of needing person 2 for one return. A search over all states finds a minimum of 17.

Classic wrong answer. Giving 19, by assuming that the fastest person should always carry the torch. Grouping the two slowest saves more than the fast escort does.

Question 16.12 ★ QR, QT, Analyst • any • junior

You have a 3-litre jug, a 5-litre jug and plenty of water, and no other marks. How do you measure exactly 4 litres? Could you measure 3 litres with a 6-litre jug and a 10-litre jug? State the general rule.

Answer

Answer to Question 16.12.

Fill the 5, pour into the 3, leaving 2. Empty the 3, and pour in the 2. Fill the 5, and top up the 3 with 1 litre, which leaves 4. With jugs of 6 and 10 you cannot get 3.

Any amount you can make is a combination of the two sizes, so it is a multiple of their greatest common divisor. And you can reach every multiple of it up to the larger jug. For 3 and 5, the divisor is 1. For 6 and 10, it is 2, and so only even amounts arise. A search over all states of the jugs confirms the amounts {0,2,4,6,8,10}\{0, 2, 4, 6, 8, 10\}.

Classic wrong answer. Trying moves at random until the answer appears. State the rule, which also tells you when to stop.

Question 16.13 ★ QR, QT, QD • any • junior

On an 8 by 8 grid, one cell is black and all the others are white. A move flips all the cells of a row or all the cells of a column. Can you reach an all-white grid? What is the invariant?

Answer

Answer to Question 16.13.

No. The parity of the number of black cells never changes, and it starts at 1.

A move flips 8 cells. If kk of those were black, the black count changes by 8−2k8 - 2k, which is even. So the count stays odd, and it cannot be 0. A long random run of moves on a grid confirms the count stays odd at every step.

Classic wrong answer. Trying to fix the one black cell by flipping its row. That makes the row black except for one cell, and the count goes to 7: odd again.

Follow-up. And on a 7 by 7 grid? A move now flips 7 cells, so the count no longer helps. Use any 2 by 2 block instead: a move flips 0 or 2 of its cells, so its parity never changes, and a block that holds the black cell stays odd. So the answer is still no, on any size of grid.

Question 16.14 ★★ QR, QT, Trader, Analyst, QD • any • junior

A hundred people stand in a line, each with a random black or white hat, and each sees all the hats in front only. From the back, each in turn says “black” or “white”, and everybody hears. They may agree on a plan first. How many can be sure of being right, and how?

Answer

Answer to Question 16.14.

Ninety-nine can be sure, and the last person at the back has an even chance. The one at the back says “black” if the number of black hats in front is odd, and “white” otherwise.

The plan encodes one bit, the parity of the 99 hats. The next person sees 98 of those hats. Comparing their parity with what was announced gives their own colour for certain. Each person in turn knows the announced parity and has heard all the answers from behind, and sees the rest, so each can work out their own hat. A simulation with 300 random lines finds no error among those 99.

So, on average, 99.599.5 are right. You cannot do better than that person’s even chance, since nobody has seen that hat.

Classic wrong answer. Pairing people so that each says what the other one wears, and saving about half for sure. That wastes the fact that everybody hears everything, and one bit is enough for all.

Follow-up. What if there are three colours? Use the sum of the colour numbers modulo 3, and say it as one of three words. Still 99 are sure. In general, one announcement carries one sum modulo the number of colours.

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

One of 1000 bottles of wine has been poisoned. A taster shows the effect exactly 24 hours after any sip, however small, and you must know the bottle in 24 hours. How few tasters do you need? How few would you need if you had 48 hours, and could use a second round with those still unaffected?

Answer

Answer to Question 16.15.

You need 10 tasters for one round, and 7 tasters for two rounds.

One round: write each bottle’s number in binary, with 10 digits, because 210=1024≥10002^{10} = 1024 \ge 1000. Taster kk sips from every bottle whose kk-th digit is 1. The set of those affected gives the digits of the poisoned bottle. You cannot do with 9 tasters, since 9 tasters produce only 512 distinct results.

Two rounds: now each taster has three possible results: affected in round 1, affected in round 2, or never. So write the bottles in base 3, with 7 digits, as 36=729<1000≤37=21873^6 = 729 < 1000 \le 3^7 = 2187. A digit of 0 means that the taster drinks in round 1, a digit of 1 means round 2, and a digit of 2 means never. A taster affected in round 1 does not need to drink in round 2, because that digit is already known.

In general, with rr rounds, tt tasters handle (r+1)t(r + 1)^t bottles.

Classic wrong answer. Using 1000 tasters, or a binary search, which takes 10 days. Group testing in parallel is about designing one test whose results encode many bits at once.

Why it matters. This is the idea behind group testing and fast fault isolation: put many things in each test, and let each one’s pattern of results be its address.

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

A table holds 100 coins, of which you are told exactly 10 show heads. You are blindfolded, and you cannot feel which side is up. Split the coins into two groups, flipping any coins that you choose, so that both groups have the same number of heads.

Answer

Answer to Question 16.16.

Take any 10 coins as the first group, and flip all of them. The two groups then have the same number of heads.

Say that the 10 you chose hold hh heads. So the other 90 hold 10−h10 - h. After you flip your 10, they hold 10−h10 - h heads as well. It does not matter how many heads you chose, which is why you do not need to see. A simulation with random arrangements gives equality each time.

Classic wrong answer. Saying that you need to feel the coins, or looking for a way of dividing them evenly. The number you need is the size of the group, and it comes from the total given, not from the coins’ positions.

Question 16.17 ★★ QR, QT, Analyst • any • junior

Can a knight start at one corner of an 8 by 8 chessboard, visit every square exactly once, and finish at the opposite corner? Give the argument. Could it finish at some other square, in principle?

Answer

Answer to Question 16.17.

No. The two corners have the same colour, but a knight’s path over all 64 squares has 63 moves, and it must end on the opposite colour from where it started.

Every knight’s move changes the colour of the square. After 63 moves, an odd number, you are on the opposite colour. Opposite corners of the board have the same colour, because (0+0)(0 + 0) and (7+7)(7 + 7) are both even. So it is impossible.

The argument forbids only the same colour, so a finish on the other colour is allowed by this argument. It does not by itself prove such a path exists. On small boards you can test the rule by exhaustive search: on a 4 by 4 board, no tour joins opposite corners, while on a 5 by 5 board, with 24 moves, such a tour exists.

Classic wrong answer. Trying to draw a tour and failing. A failure to find a tour says nothing, and on larger boards you would not finish. Parity is one line.

Question 16.18 ★★ QR, QT, Analyst • any • junior

One square is removed from a 2n2^n by 2n2^n board, any square at all. Show that the rest can be covered by L-shaped pieces of three squares. How many pieces are used on an 8 by 8 board?

Answer

Answer to Question 16.18.

Use induction on nn. An 8 by 8 board uses 21 pieces.

For n=1n = 1, a 2 by 2 board with one square removed is an L piece. Now take a 2n2^n by 2n2^n board with a square removed. Split it into four quadrants. The missing square lies in one quadrant. Place one L piece at the centre of the board so that it takes one square from each of the other three quadrants. Now each of the four quadrants has exactly one missing square, and each is a smaller board of the same type.

The count is (64−1)/3=21(64 - 1)/3 = 21, and 4n−14^n - 1 is always divisible by 3. A program carrying out this construction, for each of the 64 positions of the hole, covers everything with 21 pieces of three squares.

Classic wrong answer. Assuming that the count alone gives the answer. That only shows that the numbers fit, and a colouring could still forbid some positions. The induction gives you a real covering.

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

An island has 13 red, 15 green and 17 blue chameleons. When two of different colours meet, both change to the third colour. Could all the chameleons ever be the same colour? What if the counts were 13, 16 and 16?

Answer

Answer to Question 16.19.

Not with 13, 15 and 17. With 13, 16 and 16, yes.

When two meet, one colour count goes up by 2 and two go down by 1. So the difference between any two counts changes by 0 or by ±3\pm 3, and it is unchanged modulo 3. If all were one colour, two counts would be 0, with a difference of 0. In 13, 15, 17, the residues are 1, 0, 2, all different, so no two counts can ever be equal modulo 3.

With 13, 16 and 16, two counts agree. Let them meet: each meeting of green and blue reduces both, and 16 meetings turn them all red. A search over all reachable states confirms the two answers.

Classic wrong answer. Thinking of parity, as with so many invariants. A meeting changes the counts by 1 and 2, so parity is not preserved, and the right modulus is 3.

Question 16.20 ★★ QR, QT, QD • any • junior

The numbers 1 to 10 are on a board. A move wipes out any two numbers aa and bb and writes ∣a−b∣|a - b|. After nine moves, one number is left. Can it be 0? Separately, if each move instead writes a+b+aba + b + ab, what is the last number, and does the order matter?

Answer

Answer to Question 16.20.

It cannot be 0, since the parity of the sum never changes and it starts odd. The second game always ends in 11!−1=39 916 79911! - 1 = 39\,916\,799, whatever the order.

First, ∣a−b∣|a - b| has the same parity as a+ba + b, so each move keeps the parity of the total. The total starts at 55, which is odd, so the last number is odd.

Second, note that a+b+ab=(a+1)(b+1)−1a + b + ab = (a + 1)(b + 1) - 1. So the product of x+1x + 1 over all the numbers on the board does not change. It starts as 2⋅3⋯11=11!2 \cdot 3 \cdots 11 = 11!, and at the end it is the last number plus one. Random orders in a simulation all confirm these two results.

Classic wrong answer. Trying a few orders to look for a pattern. Any invariant will be easier to find by asking what a move preserves.

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

You have 100 distinct numbers. How many comparisons do you need to find both the largest and the smallest, if done cleverly, rather than the 198198 of two separate scans? Give the method, and the formula for nn numbers.

Answer

Answer to Question 16.21.

Use 148 comparisons for 100 numbers. In general it is ⌈3n/2⌉−2\lceil 3n/2 \rceil - 2.

Compare the numbers in pairs. Each pair uses one comparison, and then the larger of each pair competes for the maximum, and the smaller of each pair for the minimum. For n=100n = 100: 50 comparisons in pairs, then 49 for the maximum, and 49 for the minimum, giving 148. A count over real arrays of various sizes confirms the formula.

Why it is hard to beat: to finish, n−1n - 1 numbers must have lost once, and n−1n - 1 must have won once, so 2n−22n - 2 units of information are needed. A comparison between two untouched numbers gives 2 units, and any later one gives at most 1 against an adversary. There are at most n/2n/2 of the first type.

Classic wrong answer. Using 198198 comparisons, or claiming that sorting first is good. Sorting costs about nlog⁡2nn\log_2 n. Using a single scan for both ignores what each comparison can tell you.

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

A census taker asks a woman the ages of her three daughters, as whole numbers. She says the product of the ages is 36, and the sum is the house number next door. The taker looks at that number and still cannot tell. She adds that the eldest plays the piano. What are the ages, and what must the house number be?

Answer

Answer to Question 16.22.

The ages are 2, 2 and 9, and the house number is 13.

List the triples with product 36. There are eight: (1,1,36)(1, 1, 36), (1,2,18)(1, 2, 18), (1,3,12)(1, 3, 12), (1,4,9)(1, 4, 9), (1,6,6)(1, 6, 6), (2,2,9)(2, 2, 9), (2,3,6)(2, 3, 6), (3,3,4)(3, 3, 4). Their sums are 38, 21, 16, 14, 13, 13, 11 and 10. The census taker sees the number, and still cannot tell, so it must be a sum that appears twice: 13. Then “the eldest” rules out (1,6,6)(1, 6, 6), where the two oldest are the same age.

Classic wrong answer. Stopping when the sum looks ambiguous to you. The information is in the fact that the census taker could not decide, which is a statement about the taker’s view, not yours.

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

Three perfect logicians stand in a line, each seeing the hats in front. The hats were taken from a box of 3 red and 2 white. The one at the back says, “I do not know my colour.” The one in the middle says, “I do not know either.” The one at the front, who sees nobody, says, “I know mine.” What colour, and how?

Answer

Answer to Question 16.23.

The hat at the front is red.

There are only 2 white hats, so if the back person saw two white hats, they would know that their own is red. They say they do not know, so the middle and the front are not both white. The middle person knows this. If the front hat were white, the middle person would see it and know that their own must be red. But the middle person does not know, so the front hat is not white.

The front person sees nobody, and works from what the other two said. Each “I do not know” is a piece of information about what they saw.

Classic wrong answer. Saying that the front person has no information because they see nothing. Each statement narrows the possible worlds, from seven down to those with a red hat at the front.

Question 16.24 ★★ QR, QT, QD • any • junior

There are 10 stacks of coins. Each stack is either all genuine, at 10 grams a coin, or all fake, at 11 grams a coin, and any number of stacks may be fake. You may use an accurate scale once. How do you find all the fake stacks? How many coins do you need in all?

Answer

Answer to Question 16.24.

Take 2k−12^{k - 1} coins from stack kk: 1, 2, 4, up to 512, for 1023 coins. The excess in grams, written in binary, lists the fake stacks.

Each subset of stacks must give a different excess. Powers of 2 do this, because every number has a unique binary expansion. The 1024 possible subsets need 1024 distinct excesses, starting from 0, so a total of at least 1023 extra grams must be possible, which means at least 1023 coins, and the powers of 2 reach this bound. An exhaustive check of all 1024 subsets agrees.

Classic wrong answer. Using 1, 2, 3, up to 10, as you would for a single fake stack. Then 3 might mean stack 3, or stacks 1 and 2 together.

Question 16.25 ★★ QR, QT, Analyst • any • junior

You stand at a fork, with one road leading to safety and the other not. Two guards know the road. One always tells the truth and the other always lies, and you do not know which is which. With one yes-or-no question to one guard, how do you find the safe road? Show that your question works in all four cases.

Answer

Answer to Question 16.25.

Ask one guard, “Would you say yes if I asked you whether the left road is safe?” A yes means that left is safe, in all cases.

Check it. If left is safe and the guard is truthful, the direct answer would be yes, and they say yes. If left is safe and the guard lies, their direct answer would be no, and they lie about that, so they say yes. If left is not safe, the truthful guard says no, and the liar’s direct answer would be yes, which they lie about, so they say no.

Another form uses the other guard: “Would the other guard say that left is safe?” Here the answer is always false, so a no means that left is safe. An exhaustive check of the four cases confirms both.

Classic wrong answer. Asking a question that identifies the liar, such as “Is two plus two four?” This uses your only question on something other than the road.

Question 16.26 ★★ QR, QT, Analyst • any • junior

A notebook has 100 numbered statements. Statement kk says, “Exactly kk of the statements in this notebook are false.” Which statements are true? Would your answer change if it said “at least kk”?

Answer

Answer to Question 16.26.

Statement 99 is the only true one. With “at least kk”, statements 1 to 50 are true, and the rest are false.

At most one “exactly” statement can be true, because they contradict one another. If none were true, all 100 would be false, which would make statement 100 true: a contradiction. So exactly one is true, and 99 are false, which makes statement 99 the true one.

For “at least kk”, suppose that ff statements are false. The true ones are exactly those with k≤fk \le f, so there are ff true ones. Hence 100−f=f100 - f = f, and f=50f = 50. A search over all possible numbers of false statements finds that each version has one solution.

Classic wrong answer. Choosing statement 100, because it is the last one. If it were true, all 100 would be false, including itself.

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

You have 12 balls, of which exactly one is odd: heavier or lighter, you do not know which. With a balance, find the odd ball and whether it is heavy or light, in 3 weighings. Why is 13 balls impossible in this form, even though 33=273^3 = 27 outcomes appear to be enough? Give a scheme of weighings fixed in advance.

Answer

Answer to Question 16.27.

Use a fixed scheme: weigh {1,2,3,10}\{1, 2, 3, 10\} against {4,5,6,11}\{4, 5, 6, 11\}, then {1,2,3,11}\{1, 2, 3, 11\} against {7,8,9,10}\{7, 8, 9, 10\}, and then {1,4,7,10}\{1, 4, 7, 10\} against {2,5,8,12}\{2, 5, 8, 12\}. Thirteen balls cannot be done.

Each ball has a pattern over the three weighings, ++, −- or 00 for left, right or out. If the ball is heavy, that pattern is the outcome. If it is light, it is the negative of that pattern. So all 24 cases must give different outcomes, and the pattern of each ball must not be the negative of another’s. In this scheme, ball 1 is (+,+,+)(+, +, +), ball 2 is (+,+,−)(+, +, -), ball 10 is (+,−,+)(+, -, +) and ball 11 is (−,+,0)(-, +, 0). An exhaustive check confirms that the 24 outcomes are all different and none is level in all three.

Now for why 13 fails: 27−1=2627 - 1 = 26 outcomes and 13⋅2=2613 \cdot 2 = 26 cases seem to fit exactly. But look at the first weighing. Put aa balls on each pan. If it tips, there are 2a2a cases left, and two weighings have 9 outcomes, so a≤4a \le 4. If level, there are 13−2a13 - 2a balls left, hence 2(13−2a)2(13 - 2a) cases, so that must be at most 9, which gives a≥5a \ge 5. These contradict each other.

Classic wrong answer. Thinking that 33=273^3 = 27 settles the count. That count is a bound. You also need a first step that splits the cases evenly, and the need for equal numbers on both pans rules this out for 13.

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

Can a 10 by 10 board be covered exactly by straight 1 by 4 bricks? What about a 4 by 10 board, and what is the general rule for an mm by nn board with 1 by 4 bricks? Give the colouring that decides it.

Answer

Answer to Question 16.28.

No for 10 by 10, and yes for 4 by 10. An mm by nn board can be covered exactly when 4 divides mm or nn.

Colour the cell at (x,y)(x, y) with (x+y) mod 4(x + y) \bmod 4. Each straight brick covers one cell of each of the four colours, whichever way it lies. On a 10 by 10 board, the colour counts are 25, 26, 25 and 24, which are not equal. So no covering exists.

For the general rule, use a stronger colouring. Put the number ix+yi^{x + y} on each cell, with i2=−1i^2 = -1. A brick has four consecutive powers of ii, and they add up to 0. So the sum over a covered board is 0. But the sum over the board is

(∑x=0m−1ix)(∑y=0n−1iy),\Bigl(\sum_{x = 0}^{m - 1} i^x\Bigr)\Bigl(\sum_{y = 0}^{n - 1} i^y\Bigr),

and a sum of consecutive powers of ii is 0 only when its length is a multiple of 4. So 4 must divide mm or nn. And if it does, laying the bricks in lines is enough. An exhaustive search for all sizes up to 7 by 7 agrees with this rule.

Classic wrong answer. Using the total count of cells. A 10 by 10 board has 100 cells, which is divisible by 4, and it still cannot be covered. A count is only a first check.

Question 16.29 ★★★ QR, QT, QD, Dev • any • junior, experienced

How many comparisons are needed to find the second-largest of 64 distinct numbers, compared with two separate scans? Give the method, and the formula for nn numbers. Why must every number but two lose a comparison to something other than the largest?

Answer

Answer to Question 16.29.

For 64 numbers, 68 comparisons, against 63+62=12563 + 62 = 125 for two scans. In general it is n+⌈log⁡2n⌉−2n + \lceil \log_2 n \rceil - 2.

Run a knockout tournament: n−1n - 1 comparisons, which find the largest. The second-largest must have lost directly to the largest, because it could not lose to anything else. So it is among the numbers that the winner beat, of which there are ⌈log⁡2n⌉\lceil \log_2 n \rceil. Scan those for the largest with ⌈log⁡2n⌉−1\lceil \log_2 n \rceil - 1 more comparisons. For n=64n = 64, that is 63+563 + 5. A run on random arrays gives the second-largest correctly, with a worst case of exactly 68.

Why it must be so: you must know that every number except the top two is not second. The only proof that a number is not second is that it lost to something other than the largest. Otherwise, it could yet be second. So n−2n - 2 numbers need a loss to a non-largest. On top of that, the largest has to win its own comparisons, and an adversary can make it win at least ⌈log⁡2n⌉\lceil \log_2 n \rceil of them, none of which count toward the first group.

Classic wrong answer. Sorting, or removing the largest and rescanning, for 125 comparisons. That second scan repeats comparisons whose results you already know.

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

A group of nn people each get a hat, with any of nn colours, and repeats allowed. Each sees all the hats except their own, and they all guess at the same moment. They may agree on a plan first. Find a plan that guarantees that exactly one person is right, whatever the hats are.

Answer

Answer to Question 16.30.

Number the people from 0 to n−1n - 1, and the colours from 0 to n−1n - 1. Person kk guesses the colour that would make the sum of all colours equal kk modulo nn. Exactly one is right.

Let SS be the true sum, modulo nn. Person kk sees all hats but their own, and assumes that the total is kk. So person kk is right exactly when S=kS = k. As SS takes one value from 00 to n−1n - 1, exactly one person is right.

Every person is right with chance 1/n1/n, as they must be, because each hat is independent of what they see. The total number of correct guesses across the group always has a mean of 1. Without a plan, this number varies, and it may be 0. The plan removes all of the variance. An exhaustive check of all arrangements for nn up to 5 finds exactly one right guess every time.

Classic wrong answer. Thinking that a plan must raise each person’s chance. It cannot, so it must change only how right guesses overlap.

Why it matters. Diversification works the same way. You cannot change each bet’s expected payoff, but you can arrange the correlation so that exactly one pays in each state.

Question 16.31 ★★★ QR, QT, Trader • hedge fund • junior, experienced

Three people each get a random black or white hat. Each sees the two other hats, and at the same moment they guess their own colour or pass. The group wins if at least one guesses and all guesses are right. They may agree on a plan first. What win chance can they reach, and why does it not break the rule that each guess is right half of the time?

Answer

Answer to Question 16.31.

They can win with probability 3/43/4. The plan: if you see two hats of the same colour, guess the opposite colour. If you see two different hats, pass.

There are eight outcomes. In the 6 with two of one colour and one of the other, the person with the odd hat sees two equal hats and guesses correctly, and the other two see different hats and pass. That is a win. In the two where all three match, all three guess wrongly, which is a loss.

Each guess is still right half of the time. Across the eight outcomes, the plan makes 12 guesses: 6 are right, one in each of the winning outcomes, and 6 are wrong, all in the two losing outcomes. The plan piles the wrong guesses up into a few outcomes.

No plan beats this. Right and wrong guesses are equal in number for any plan. Each winning outcome needs at least one right guess, and each losing outcome has at most 3 wrong ones. So wins ≤3×\le 3 \times losses, which gives at most 66 of 8. A search over all 81381^3 plans confirms a maximum of 6.

Classic wrong answer. Saying that the chance is 1/21/2, because any guess has chance 1/21/2. Only the group result counts, and a plan changes how right and wrong guesses overlap, not their total numbers.

Follow-up. And with seven people? A win chance of 7/87/8, using the Hamming code of length 7: guess only if the hats you see, with some colour for your hat, would be a codeword, and choose the other colour.

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

On an island live 100 people with blue eyes and 100 with brown, and nobody knows that those are the only colours possible. No one may discuss eye colour, there are no mirrors, and anyone who works out their own eye colour leaves at midnight of that day. A visitor announces to all, “At least one of you has blue eyes.” What happens? What new information did the visitor give, when everybody could already see blue eyes?

Answer

Answer to Question 16.32.

All 100 blue-eyed people leave together on the 100th midnight, and nobody else leaves. The visitor made a fact common knowledge, which it was not before.

Use induction on the number kk of blue-eyed people. If k=1k = 1, that person sees no blue eyes, and leaves on night 1. If k=2k = 2, each sees one blue-eyed person. Each thinks, “If I am not blue, the other will leave tonight.” The other does not, so both leave on night 2. In general, each of kk blue-eyed people sees k−1k - 1, and waits to see whether those leave on night k−1k - 1. When they do not, they all leave on night kk. A brown-eyed person sees 100 blue, and when those leave on night 100, learns only that their own eyes are not blue, which does not give their colour.

What was new? Everybody knew that someone had blue eyes. But with two blue-eyed, A does not know that B knows. With three, A does not know that B knows that C knows. With 100, the chain of “knows that” has to be 100 levels long, and it stops short without a public statement. The announcement makes every level true at once. A possible-worlds simulation with up to 5 blue-eyed people among 6 reproduces the days.

Classic wrong answer. Saying that nothing happens, since the visitor told them nothing they did not know. The first level of knowledge did not change. The higher levels, what each knows about what others know, did change.

Why it matters. Public news can move a market even when everybody knew it privately. If you do not know that others know, you act differently from when you do.

Question 16.33 ★★★ QR, QT, DS, QD • any • junior, experienced

A hundred prisoners may plan once and are then kept apart. Each day, one prisoner chosen at random visits a room with a light switch, which starts off, and may toggle it. Anyone may declare “all of us have visited”. If this is right they go free, and if it is wrong they all stay. Find a plan that is certain to work. How long does it take on average?

Answer

Answer to Question 16.33.

One prisoner is the counter. Each of the others turns the light on the first time that they find it off, and never again. Only the counter turns it off, and adds 1 each time. When the counter reaches 99, they declare. This takes about 10 41810\,418 days on average, or about 28.528.5 years.

It cannot fail, because the count only goes up when someone new has signalled. The switch starts off, so there is no false count from the start. Each of the 99 non-counters turns the light on at most once.

The time is a sum of two waits for each of the 99 signals. If 100−k100 - k non-counters have not yet signalled, one of them comes along after 100100−k\frac{100}{100 - k} days on average. Then the counter must come, which takes 100 days on average. So

∑k=199(100100−k+100)=100H99+9900≈10 418.\sum_{k = 1}^{99} \Bigl(\frac{100}{100 - k} + 100\Bigr) = 100 H_{99} + 9900 \approx 10\,418.

Nearly all of this is waiting for the counter. A simulation of the plan gives a mean within 1.5%1.5\% of this.

Classic wrong answer. Declaring after some large number of days, on the grounds that everyone must have visited by then. That can be made very likely, but the question requires certainty. A count is sure, and any time limit is not.

Follow-up. What if the switch’s start is unknown? Then count to twice as much: each non-counter turns it on twice, and the counter stops at 2⋅99=1982 \cdot 99 = 198, which takes about twice as long. The one initial false count cannot reach the total by itself.

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

A chessboard has a coin on each of its 64 squares, heads or tails, in an arrangement chosen by a hostile jailer, who also points to one square. Prisoner A sees all this and must flip exactly one coin. Prisoner B then enters, sees only the coins, and must name the square the jailer chose. They may plan before. Find the plan, and say what is special about 64.

Answer

Answer to Question 16.34.

Number the squares from 0 to 63. Let PP be the exclusive-or of the numbers of all squares that show heads. Prisoner A flips the coin at square P⊕tP \oplus t, where tt is the target. Prisoner B computes the new PP, which equals tt. The method works exactly when the number of squares is a power of 2.

Flipping the coin on square ss changes PP to P⊕sP \oplus s, whether that coin was heads or tails, because a number’s own exclusive-or with itself is 0. So A wants P⊕s=tP \oplus s = t, which is s=P⊕ts = P \oplus t. This is always a valid square, as PP and tt both have 6 bits. So every target is available to A, in exactly one flip. A test with random boards and targets finds no failure.

What is special about 64: the plan assigns a square to each arrangement, and from any arrangement, one flip must reach each target. On the cube of arrangements with nn coordinates, each corner has nn neighbours, and all nn colours have to appear among them. So each colour is on exactly 2n/n2^n/n corners, and nn must divide 2n2^n. So nn must be a power of 2. An exhaustive search for three squares finds no colouring, as this argument predicts.

Classic wrong answer. Trying a parity on rows and columns separately, which handles a few bits but cannot do all six at once. Each bit of the address must be controlled by a set of squares that overlaps the others in the right way, and exclusive-or gives you that.

Why it matters. This is a perfect code. One changed bit carries exactly log⁡2n\log_2 n bits of information, and the same idea underlies the Hamming code used to correct errors in memory.

Question 16.35 ★★★★ QR, QT, Trader • hedge fund • experienced

A member of the audience picks 5 cards from a standard deck and hands them to an assistant. The assistant returns one of them to the audience, and lays the other 4 in a row, face up, in an order of the assistant’s choice. A magician, who has seen nothing else, names the hidden card. How does the system work? Do a counting argument to show how far above 52 it could go.

Answer

Answer to Question 16.35.

Among 5 cards, two share a suit. The assistant hides one of those and puts the other first, to fix the suit and a base rank. The other three cards, in one of 6 orders, tell the distance from base to hidden. A counting argument allows up to 124 cards.

There are 13 ranks in a circle, so one of the two same-suit cards is at most 6 steps clockwise from the other. Show the card from which you count, and hide the other. Order the remaining three, using a fixed order of all cards, to encode the distance dd from 1 to 6, since 3!=63! = 6. The magician reads the first card, adds dd on the circle, and keeps the suit. A test with 40 000 random hands recovers the hidden card every time.

For the counting bound with a deck of nn cards, each hand must be sent to a different row of 4 cards. There are (n5)\binom{n}{5} hands, and n(n−1)(n−2)(n−3)n(n - 1)(n - 2)(n - 3) rows. That needs n−4120≤1\frac{n - 4}{120} \le 1, and so n≤124n \le 124. It can be reached: each hand can use 120 rows (5 choices of a hidden card times 4! orders), each row suits n−4n - 4 hands, and with n−4≤120n - 4 \le 120, a matching exists by Hall’s theorem. That proof gives no easy formula.

Classic wrong answer. Saying that 4! = 24 orders cannot code a card out of 48. The assistant also chooses which card to hide, and that gives 5 times the freedom. With the suit given by the first card, you only need a small part of that.