_ [Contents]

Copyright © 2004 jsd

1  Statement of the Puzzle

Version 1a: You are given twelve coins. All appear to be identical, as far as you can tell, but you are told that one of them is a counterfeit. All genuine coins have the same mass, while a counterfeit is either lighter or heavier than a genuine coin.

You are allowed to weigh coins using a two-pan equal-arm balance (sometimes called a scale or scales), as shown in figure 1. The balance provides one of three possible indications: the right pan is heavier, or the pans balance, or the left pan is heavier. The balance has sensitivity sufficient for the task. Note that the result is qualitative not quantitative: there is no indication of how much heavier the heavy pan is.

libra
Figure 1: Two-Pan Equal-Arm Balance

Your mission, should you decide to accept it, is to identify the countefeit coin and tell whether it is “light” or “heavy”, using at most three weighings.

You are not allowed to tamper with or scrutinze the coins, nor gather any information about them except by the three weighings. You may, if you wish, label the coins if that helps you keep track of which is which.

Version 2a: Same as version 1a, but you are told that at most one of the coins is a countefeit, i.e. possibly all 12 are genuine.

Version 1b: Same as version 1a, with the added restriction that we want a parallel algorithm. That is, you must decide in advance (before any weighings are carried out) which coins are to be weighed in each of the three weighings. Most people are tempted to use the results of the first weighing to help design the subsequent weighings, but that is disallowed in this version.

Having a parallel algorithm means, among other things, that the three weighings can be performed in any order.

Version 2b: Same as version 2a, with a parallel algorithm.

Beginners are encouraged to start with version 1a, which is the easiest. In this note we will solve version 2b, which is the hardest, and which includes all the other versions as immediate corollaries.

Extended versions: There are four more versions x1a through x2b, the same as the above, except that there are thirteen unknown coins, and you are allowed to supply one known-good coin of your own and use it in the weighings however you like.

2  Information-Theory Analysis

This is an example of what scientists call a “Design of Experiment” (DoE) question. Entire books have been written about DoE.

Let’s start by reconnoitering the situation using the methods of information theory. For a nice, accessible introduction to information theory, see reference 1.

The first step is to calculate the entropy,1 i.e. how much we don’t know about the problem. In version 1, there are 24 possible outcomes:2 perhaps coin #1 is heavy, perhaps coin #2 is heavy, and so forth for twelve possibilities, plus another twelve possibilities if the counterfeit coin is light. Invoking the minimax3 principle, we assume that these 24 outcomes are equally likely. That gives us a total entropy of

S = log2(24) = 4.585 bits 
S = log3(24) = 2.89 trits
             (1)

We get to compare this with the information we hope to get. The balance provides only three possible results per weighing. If we are lucky, we might hope that the results are equally likely, or nearly so, in which case the weighings might provide us with information

I <= log2(27) = 4.755 bits
I <= log3(27) = 3 trits
             (2)

That is, the most we dare hope for is to get 1 trit of information per weighing.

As an example of bad design, consider for a moment what happens if the first weighing involves three coins in the left pan, three coins in the right pan, and six bystanders. There is a distinct possibility that the pans will balance. That tells us that the counterfeit is among the six bystanders. So we are left with a reduced version of the original problem: six coins with two weighings remaining. Information theory tells us that this reduced problem is, alas, provably impossible. There are twelve possible outcomes (which coin, light or heavy) but there are only nine possible results of the remaining weighings. That is, we have 2.26 trits of entropy remaining but at most 2 trits of information available. This is a hopeless situation.

As an example of much better design, consider what happens if the first weighing involves four coins in each pan plus four bystanders. This has the nice property that the three possible outcomes (left heavy, balance, right heavy) are equiprobable, so the first weighing returns the maximum possible information, i.e. one full trit.

Suppose the pans balance. We are left with a reduced version of the problem: four coins with two weighings remaining. This problem is not hopeless: we have eight possible outcomes (1.89 trits of entropy) and we have a reasonable hope of getting sufficient information from the remaining weighings.

Now suppose the pans don’t balance. This leaves us with eight coins and two weighings remaining. However, there are only eight possible outcomes (not sixteen), since once we identify which of the eight coins is the counterfeit, we know (based on the results of the first measurement) whether it is heavy or light. So once again we have eight possibile outcomes (1.89 trits of entropy) with two weighings remaining, so there is hope.

Additional examples of this sort of hypothesis testing can be found in reference 2, reference 3, and reference 4.

3  Communication-Theory Analysis

Let’s treat the balance as a sort of communication channel. That is, suppose it is trying to transmit to you a code telling you the answer to the puzzle. The channel has an alphabet with only three symbols (L, B, and R) denoting respectively left-pan heavy, balance, and right-pan heavy. The channel can give you only a single codeword consisting of three such symbols. So the overall task reduces to this: using some subset of the 27 possible codewords, we want to assign a codeword to each coin. The codeword must be unique to that coin, and the set of codewords must obey certain constraints as discussed below.

First, let’s just look at all 27 codewords. It is easy to construct this table; it’s just counting in base 3.

RRR    13
RRB    12
RRL    11
RBR    10
RBB    9
RBL    8
RLR    7
RLB    6
RLL    5
BRR    4
BRB    3
BRL    2
BBR    1
BBB    0
BBL    -1
BLR    -2
BLB    -3
BLL    -4
LRR    -5
LRB    -6
LRL    -6
LBR    -8
LBB    -9
LBL    -10
LLR    -11
LLB    -12
LLL    -13
             (3)

Now, suppose you pick one of the codewords such as RRB and paint it on one of the coins. You can think of the codeword in two ways:

At this point the alert reader will be wondering what happens if the coin we marked RRB is lighter than a genuine coin. Then the balance will report LLB, that is, left-pan heavy, left-pan heavy, neutral balance. From this we conclude that if we have marked one of the coins RRB, we must not mark any of the other coins LLB, lest there be ambiguity. More generally, every time we use a codeword from the list in equation 3, we must “burn” its mirror-image code.

Consequently, even though it appears we have 27 codewords, this approach has no chance of handling more than 13 coins. Since we are only required to handle 12 coins, things are still on track.

There is one other constraint: The balance is only capable handling an equal number of coins in the two pans. So we must choose a set of codewords (a subset of equation 3) with the property that in each of the three columns the number of Rs equals the number of Ls.

The design process proceeds as follows: We immediately discard the BBB code as being unsuitable for marking on any coin ... since a coin that participates in none of the weighings can never be properly characterized.4 Now take the top half of equation 3 i.e codes 1 through 13 as a tentative set of codewords. We get to discard one, because we only need 12. The obvious choice is to discard the RRR code, because by doing so we create an even number of Rs and Ls in the remaining set. Finally, we replace four of the codes by their mirror images. (Remember, we get to use any given code or its mirror image.) We need to do some mirroring because the tentative set started out too rich in Rs in the first column, and we need to turn four of them into Ls. To make a long story short, it suffices to mirror codes 12, 11, 9, and 7. The result is:

LLB    -12
LLR    -11
RBR    10
LBB    -9
RBL    8
LRL    -7
RLB    6
RLL    5
BRR    4
BRB    3
BRL    2
BBR    1
             (4)

If you scrutinize equation 4, you will discover the following nice properties:

The codewords in equation 4 solve version 1 of the problem directly. They also solve version 2, if we adjoin the observation that if the balance generates the BBB codeword it means no counterfeit is present.

To solve the extended versions of the puzzle, adjoin the RRR codeword to equation 4 and put the known-good coin in the left pan.

4  Geometric Interpretation

In the language of Design of Experiment, these twelve codewords are the test vectors.

If you are good at visualizing things in higher dimensions (most people aren’t) it may be amusing to visualize these test vectors as shown in figure 2.

12coins
Figure 2: Test Vectors for the Twelve-Coins Puzzle

If you scrutinize the figure, you can discover quite a number of interesting properties.

5  For Further Reading

1.
John R. Pierce, Symbols, Signals, and Noise

2.
For a general discussion of what entropy is, see ./thermo-laws.htm#sec-entropy

3.
John Denker, “Twenty Questions” ./twenty-questions.htm

4.
John Denker, “Teaching (and Learning) Thinking Skills” ./thinking.htm

1
For a general discussion of what entropy is, see reference 2.
2
The analysis of version 2 is left as an exercise for the reader.
3
By way of analogy: when you are playing chess, you should plan your moves on the assumption that your opponents will make their best moves; you shouldn’t assume they are going to make things easy on you. In this case, if the possibilities were not equiprobable, the entropy would be less and the puzzle would be easier.
4
The BBB code will resurface below, in connection with version 2 of the puzzle, in the case where none of the coins is counterfeit.
[Contents]

Copyright © 2004 jsd

_