Find the coin

Logic Level 3

You have 11 visually identical coins. One of them is marked genuine (and you know which one this is). Out of the remaining 10 coins, all but one of them are also genuine, but you don't know which ones. The remaining odd coin has a different weight, either heavier or lighter than the others.

You have a regular two-pan balance. This works like you expect: you load a certain number of coins to each side, and the balance will tell you the heavier pan (or whether they have equal weight).

How many weighings are necessary in the worst case to find the odd coin and determine whether it weighs more or less than genuine coins?


The answer is 3.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

3 solutions

Kostub Deshmukh
Jan 9, 2016

You can find the unbalanced coin in 3 weighings as follows:

  1. Remove the known balanced coin as it isn't very useful. Divide the remaining 10 coins into 4 sets A , B , C , D A, B, C, D of size 3, 3, 3, 1 respectively.
  2. Weighing 1: Compare A A and B B .
  3. Weighing 2: Compare A A and C C .
  4. If A = B = C A = B = C , then we know that the unbalanced coin is in D D . To determine whether it is heavier or lighter we compare it with the known coin and we are done in 3 weighings.
  5. If A B A \ne B and A C A \ne C , we know that the unbalanced coin is in A A and we know whether the coin is heavier or lighter depending if A > B A > B or A < B A < B . We choose A A and proceed to step 7.
  6. If A B A \ne B and A = C A = C , we know the unbalanced coin is in B B . We also know if it is heavier or lighter depending if A < B A < B or A > B A > B . We choose B B and proceed to step 7. The case when A = B A = B and A C A \ne C is analogous as the coin is in C C .
  7. Weighing 3: Take the 3 coins in the chosen set and put two of them on the scale. If they are equal the the remaining coin is the unbalanced coin. If they are unequal, since we already knew in the previous step whether the unbalanced coin is heavier or lighter, choose the corresponding coin from the scale.

No, the question is "Find the number of weights that are necessary to find the unbalanced coin and establish if it weights more or less". With your algorithm you only find the coin, but you can't answer to the second question.

Dario Alise - 5 years, 5 months ago

Log in to reply

Yes I can. Knowing whether it weighs more or less is crucial in identifying the coin. See steps 5 and 6 for establishing if the unbalanced coin is weighs more or less. The one case where it wasn't determined was step 4. I edited the solution slightly to include that.

Kostub Deshmukh - 5 years, 5 months ago

Log in to reply

Okay, misunderstand. If you remove the balanced coin, you have the same algorithm that I described in my post. Infact the function f, that give the number of weights, for n = 10, require exactly 3 weights. If you remove the balanced coin, you have exactly ten coins. I think that is not clear in my question that you must use all the coins :)

Dario Alise - 5 years, 5 months ago

Log in to reply

@Dario Alise If you remove the balanced coin, your algorithm doesn't work since it requires knowledge of one balanced coin. It might be possible to rewrite it without requiring one. I haven't investigated it in detail.

Anyway for this question, 4 is marked as the correct answer when in fact it should be 3.

Kostub Deshmukh - 5 years, 5 months ago

Log in to reply

@Kostub Deshmukh No, i think you not understand how my algorithm work. He is the same of your, infact he work also if you don't know what is the balanced coin. If you have ten coins with my algorithm: 1) You can divide the ten coins (including the balanced that you can't exclude!) in three set of three coins A, B, C, and D that has one coin. 2) You weight A and B, if they are equal you weight A and C, if they are equal, you know that D is unbalanced and finally you can put D and balanced coin on the scale to determine if D weight more or less.

The other case are the same, try it :)

Dario Alise - 5 years, 5 months ago

@Kostub Deshmukh I try to explain: 1) The simple case to recognize the coin, when you know if the unbalanced coin weights more or less is to have a set that have only three coins: infact, weights two of them, you can find it. 2) Your algorithm, same the mine, require two weight to identify if the coin weights more or less. 3) You can imagine it as a ternary tree. Ever level in the tree can work on set that contains max 3^k money. So with 1 weight you can recognize 1 coin of 3, with 2 weight you can recognize 1 coin of 9 (divide in three set, weight two of them, if the former weight more/less the latter, it contains the coin, so you can split it and test two coins of them, exactly how the last case) So after the two weights that are necessary to establish if the coins weights more or less, you can examine other 3^w coins where w number of weights. It's all? NO. Because if for example N=30, you can have max three set A, B, C with 9 coins, and D with 3 coins. You can't build three set of ten coins because it require one more weights. But there is another case to include. If A=B=C, it means that D contains the unbalanced coins, but you don't know if weights more or less because you never try to weight this set. So the third weight is test the set D with a subset of A or B or C of three coins to establish if D weights more or less and the last weight (the fourth) is to find the coin. With my formula, that include the balanced coin in the set, you have that with N = 3 you can test max 10 coins, with N = 4 you can test max 30 coins, with N = 5 you can test 90 coins. With your with N = 3 you can test max 11 coins, with N = 4 you can test max 31 coins, and so, because you work effectively with N-1 coins :)

Dario Alise - 5 years, 5 months ago

This looks great!

In future, if you spot any errors with a problem, you can “report” it by selecting "report problem" in the “More” menu in the top right corner. This will notify the problem creator who can fix the issues.

Calvin Lin Staff - 5 years, 5 months ago

Log in to reply

Thanks Calvin. I had looked for a "report" button but couldn't find it. Maybe you should change the of the button from "View reports" to "Report problem".

Kostub Deshmukh - 5 years, 5 months ago

Log in to reply

Thanks for helping us improve Brilliant!

Currently, our system is

If you have tries left, then it will say "Report problem".
If you have no tires left, then it will allow you to "View reports" where you can also report the problem.

I agree that the phrasing is not clear, and it doesn't suggest that you are able to report it. Let me think about improving this aspect.

Calvin Lin Staff - 5 years, 5 months ago
Dario Alise
Jan 5, 2016

If N is the number of coins, calculate 3 * round( l o g 3 ( N ) log_3 (N) ) = L, that is the max large set that you can obtain. Now distinguish two case:

a ) a) 3 * L ≤ N

b ) b) 3 * L > N

If you are in the a ) a) case, split N in three set of equal number, that we can call A1, A2, A3. If N mod 3 = 1, 2, the other coin are separated: we call, if this other set exist, A4 that contain one or two coins.

Test on the scale A1 and A2 (that contain the balanced coin). You can have three situation:

1 ) 1) A1 go UP and A2 go DOWN.

2 ) 2) A1 go DOWN and A2 go UP.

3 ) 3) A1 and A2 are balanced.

In the first case, it means that A1 can contain the unbalanced coin and it weights less or A2 contain the unbalanced coin and it weights more. But most important, it means that the set A3 and, if exist A4, are balanced. In the second case, it means that A1 can contain the unbalanced coin and it weights more or A2 contain the unbalanced coin and it weights less. Also in this case, it means that the set A3 and, if exist A4, are balanced. In the third case, it means that the set A1 and A2 are balanced and in the set A3 or A4 there is the unbalanced coin.

In the 1 ) 1) case, now you weight one of the two set, for example A1, with A3 (that now we know is composed from only balanced coin). The possible result are only two:

1 ) 1) A1 go UP and A3 go DOWN (according to the first case, it means that A1 contains the unbalanced coin and it weights less)

2 ) 2) A1 and A3 are balanced (according to the first case, it means that A2 contains the unbalanced coin and it weights more)

So now you know if the coin weights more or less, than choose the appropriate set and split it in other three part.

You can have three possible situation if M is the length of the set:

I ) I) M mod 3 = 0 so you have three set of M element.

I I ) II) M mod 3 = 1 so you have two set of M element and 1 coin remain out

I I I ) III) M mod 3 = 2 so you have two set of M element and 2 coin that remain out

If you are in the case I ) I) you can test the first of three subset with the second, and choose the subset that go UP (it weights less), than repeat the splitting algorithm until you have subset with only three element, with which you can find simple the unbalanced coin.

If you are in the case I I ) II) you can use the same algorithm but if the two first that you compare are equal you can conclude that the unbalanced coin is the remained coin.

If you are in the case I I I ) III) , if the two subset are equal you can compare the two coin that remain out and you can conclude the research.

In the 2 ) 2) case, now you weight one of the two set, for example A1, with A3 (that now we know is composed from only balanced coin). The possible result are only two:

) -) A1 go DOWN and A3 go UP (according to the second case, it means that A1 contains the unbalanced coin and it weights more)

) --) A1 and A3 are balanced (according to the second case, it means that A2 contains the unbalanced coin and it weights less)

The algoritm is the same of the case 1) but with the result that are inverted.

In the third case you can test the remained set A3 with A1 or A2.

There are three possible value:

. ) .) A1 go UP and A3 go DOWN (it means that A1 contain the coin and it weights more)

. . ) ..) A1 go DOWN and A3 go UP (it means that A1 contain the coin and it weights less)

. . . ) ...) A1 and A3 are balanced (it happens only if A4 is not empty)

In the case . ) .) and . . ) ..) you can apply the splitting algorithm to find the coin, while in the . . . ) ...) case you must distinguish two case:

i ) i) A4 contain one coin: so you can weight directly with one of the other balanced coin and you can determine the nature of the coin

i i ) ii) A4 contain two coins: so you can weight A4 with two of balanced coin and reveal if A4 weights more or less then the two balanced, then you can weight the two coins and estabilish which is unbalanced.

In the case b ) b) when N > 3 * L, you obtain three set and the other money costitute A4. If A1 = A2 = A3 (to prove this you need only two weights), you can weight the set A4 with other balanced money and you can determine if A4 weight more or less, and then you can apply the splitting algorithm.

So, the total complexity of the algorithm is ceil ( log 3 ( N 3 r o u n d ( log 3 ( N ) 2 ) ) ) \log_3 (N-3^{round(\log_3 (N) -2)})) +1 weight, with N number of coins.

Finally, is interesting to see that this algorithm work fine with N > 5. For N ≤ 5, the best algorithm need two only weights, try it :D

I don't think your algorithm is optimal. For N = 11, I can do this in 3 weighings (see my solution below). It's the same algorithm you use for N=5.

I am not sure if adding the known balanced coin adds any value to the optimal algorithm.

Kostub Deshmukh - 5 years, 5 months ago

First, giving just a solution in 4 weighings is not enough, since you need to prove that it's the minimum as well.

Second, this proof of minimality will not exist, since the minimum number of weighings needed is 3; in fact, I can still complete it in 3 weighings even if there are 14 coins. Thus the current answer of 4 weighings is wrong.

Ivan Koswara - 5 years, 5 months ago

Log in to reply

14 coins, one known genuine, in 3 weighings:

Call the coins A , B , C , , N A,B,C,\ldots,N where N is the known normal coin.

Weighing 1 : Compare ABCDE versus FGHIN. There are two cases.

If Weighing 1 is balanced, then ABCDEFGHI are all genuine. Weighing 2a : Compare ABC versus JKL. There are again two cases.

If Weighing 2a is balanced, JKL are also genuine, so M is the odd coin. Weighing 3aa : Compare M versus N tells whether M is heavier or lighter.

If Weighing 2a is not balanced, then M is genuine, and we know whether the odd coin is heavier or lighter (if JKL is heavier, then since it contains the odd coin, the odd coin is heavier, and vice versa). Weighing 3ab : Compare J versus K tells which one is the odd coin (if they are balanced, then it's L, otherwise it's the corresponding heavier/lighter coin depending on whether the odd coin is heavier/lighter).

If Weighing 1 is not balanced, then JKLM are genuine. We may also assume that ABCDE is heavier; the other case is similar (reverse heavier/lighter below). The cases are either one of ABCDE is heavier, or one of FGHI is lighter. Weighing 2b : Compare ABF versus CDG.

If Weighing 2b is balanced, ABCDFG are all genuine, so the odd coin is among EHI. Weighing 3ba : Compare H versus I tells the odd coin (if they are balanced, then it's E which is heavier, otherwise it's the lighter among H and I).

If Weighing 2b is not balanced, then EHI are genuine. From the balance, we can also eliminate three coins: if ABF is heavier, then the odd coin is either one of AB which is heavier, or G which is lighter; if ABF is lighter, then it's the other way around (one of CD is heavier or F is lighter). Weighing 3bb : Compare the two possibly heavier coins (A and B in the first case, C and D in the second). This again tells the odd coin (if they are balanced, it's the other coin (G/F), otherwise it's the heavier coin).

Ivan Koswara - 5 years, 5 months ago
Ramesh Jayaraman
Jan 3, 2016

When N=9, knowledge about balanced coin is not required to identify unbalanced coin. Group to three sets of 3 coins each. Compare twice and pick the odd set. Split the odd set into three coins & repeat comparisons. So in the fourth step odd coin and it's weight relativity can be determined.

Generalizing the scenario to real and odd values of N... The answer is

2 * ceil(log3 (N))

Recursive process with total of two comparisons between three sets of coins in each level as below.

Algorithm:

Step#1 If N is multiple of 3 (N mod 3 = 0), Split it into three sets.

Step#2 Else if N mod 3 = 2, Step#2.1 If balanced coin is in the set, remove balanced coin and one extra coin and split the rest to three sets. Step#2.2 If not, either add balanced coin and split to three sets of (N+1)/2 each; or remove two extra-coins and split the rest to three sets of (N-2)/3 each. Both have same effect.

Step#3 Else If N mod 3 = 1, Remove one extra-coin and split rest into three sets of (N-1)/3 coins each.

Step#4 Perform two comparisons between three sets to pick the unbalanced set. Repeat from step#1.( If all three sets weigh the same, the extra-coin we removed is the unbalanced one)

I think that this solution is partially correct. When you compare two set, you don't know if the money weights more or less than the other. Suppose to call the money "a b c d e f g h i " and that you compare the group "abc" with "def" (this contains the balanced coin). If abc go up, and def go down, you know that the unbalanced money is in the set {a, b, c, d, f} but you don't know if it weights more (is in the set {d, f}) or weights less (is in the set {a, b, c}) Infact the general formula suggest that with 7 coins the solution require also four step (3.5), but I think that only with tre step, you can determine the coin :)

Dario Alise - 5 years, 5 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...