26

You have 50 coins which each weigh either 20 grams or 10 grams. Each is labelled from 0 to 49 so you can tell the coins apart. You have one weighing device as well. At the first turn you can put as many coins as you like on the weighing device and it will tell you exactly how much they weigh.

However, there is something strange about the weighing device. If you put coins $x_1, x_2, ..., x_j$ on the device the first time, then you have to put coins $(x_1+1) \bmod 50, (x_2+1) \bmod 50, ..., (x_j+1) \bmod 50$ on the scale the next time, and coins $(x_1+2) \bmod 50, (x_2+2) \bmod 50, ..., (x_j+2) \bmod 50$ the next time and so on. In other words, all the weighings are defined by the choice of coins you choose to weigh the first time.

Under this rule, what is the smallest number of weighings that will always tell you exactly which coins weigh 10 grams and which weigh 20?

Clearly you could just put one coin on the device in the first turn and then it would take exactly $50$ weighings to solve the problem.


Here is an example when you have only $4$ coins that takes only $3$ weighings. First put coins $1$,$2$ and $3$ on the scale. For the next weighing you will have coins $0$, $2$ and $3$. For the last weighing you will have coins $0$, $1$ and $3$ and you will then know exactly which coins are real and which are fake.


Here is another example when you have $9$ coins that takes only $6$ weighings. First put coins $2,5,7,8$ on the scale (indexing from $0$ again).

Answers so far (smaller is better)

  • 38 by san
  • 35 by Tad
  • 31 by Tad
  • 26 by joriki
  • 25 by joriki (A very impressive record!)
  • How is your example better than just weighing 1 coin at the time? In three weighing you know exactly which coins weigh 20 and which weigh 10. – Conrado Costa Jun 30 '15 at 12:34
  • @ConradoCosta If you put one coin on the scale you need 4 weighings as you weigh each coin individually. In my example that is reduced to 3. –  Jun 30 '15 at 13:25
  • In the case of $4$ coins. do you know how many weigh $20$ and how many weigh $10$? If you do then with $3$ weighing you will have found $2$ coins of the same weight. If you are lucky you may need only $2$ weighings. Or I am missing something? – Conrado Costa Jun 30 '15 at 15:21
  • @ConradoCosta No you know nothing about how many weigh 10 or 20 in advance. All the information you get has to be obtained by weighings. –  Jun 30 '15 at 15:23
  • 6
    If you let $f(n)$ denote the minimal number of weighings, for a number $n\ge1$ of coins, the sequence ${f(n)}$ starts like this: $1,2,3,3,4,5,6,6,6,7,7,8,\ldots$ This sequence does not appear in OEIS. – Tad Jul 01 '15 at 03:52
  • @Tad That's very impressive that you have computed those. How did you do it? –  Jul 01 '15 at 06:28
  • You don't need to try all $2^n$ pattern possibilities, just one from every rotation-equivalence class (it's still a lot). I used a binary search to determine, for each pattern, how many rotations were needed to get a unique signature for each "coin vector". Anyway, this confirms $f(9)=6$ as you note in response to @JonMarkPerry. Great problem - I wish I had a clue how to solve it. – Tad Jul 01 '15 at 11:27
  • @Tad That's very interesting, thank you. Would you mind sharing your code (please)? –  Jul 01 '15 at 11:28
  • Where did you come across this puzzle? It's great. Seems like it should succumb to the usual tricks, and then it really doesn't! – Dr Xorile Jul 03 '15 at 01:29
  • 1
    @DrXorile Thank you although I am afraid I made it up. There is a family of related puzzles I might pose at a later date too :) –  Jul 03 '15 at 06:10
  • $f(50)\le 35$ -- I've updated my post. – Tad Jul 03 '15 at 19:25
  • Thanks for your generous new bounty offer! In looking at other questions of yours (out of interest and also to look for ones worthy of upvotes so you can keep awarding bounties :-) I noticed this question: http://math.stackexchange.com/questions/1059379 which is related to this one. Is there any particular reason you're interested in these sort of shifted products? – joriki Jul 07 '15 at 06:15
  • @joriki Thank you! I just found a class of mathematical problems that seem open and not being a professional mathematician, I find that exciting to be honest. –  Jul 07 '15 at 06:21
  • About your comments in the new bounty box: Why do you think my argument proves $f(n)\ge n,/\log n$? What's special about the proportionality factor $1$ between $f(n)$ and $n,/\log n$? My suggestion would be to use my code to map out the currently uncharted territory between $n=26$ and $n=50$, where we can get statistics much more quickly than at $n=50$. (I'll also continue to look for solutions with $n=50$, $k=24$, of course -- unfortunately the two solutions I found for $k=25$ turned out not to work for $k=24$.) – joriki Jul 07 '15 at 06:22
  • @joriki Did you see my comment that I think in fact $f(n) \geq 2n/\log_2 n$? –  Jul 07 '15 at 06:26
  • I'm sorry, I hadn't realized that by $\lg$ you meant the binary logarithm. Then you're right about $f(n)\ge n/\lg n$ (though an argument would have to be made why it shouldn't be $\lg(n+1)$, since there are $n+1$ possible outcomes per weighing). Yes, I had seen the other comment, but I hadn't realized its significance because I wasn't thinking in terms of the binary logarithm. You have a great point there -- if we model the distribution of the individual measurements as binomial, the effective number of possible values is $~\sqrt n$, so a factor of $2$ would make sense, and it fits the data. – joriki Jul 07 '15 at 06:39
  • Sorry, no, I hadn't seen your comment, I came across it now; I thought you were taking about the remark in the bounty box :-) Sorry for all the confusion. I'll check out that reference -- interesting! – joriki Jul 07 '15 at 06:42
  • @joriki the only way there could be $n+1$ outcomes per weighing is if the pattern is all ones- but in that case you'd get the same result with every rotation. There are $d+1$ possibilities if the pattern has density $d$. – Tad Jul 11 '15 at 01:00

3 Answers3

8

Update: I've now found two solutions that require only $25$ weighings:

$$ 01011011100010111101000001100111110011010100011010\;,\\ 00101110001101001010111110001000110010011111011101\;. $$

These are the only solutions known (in the context of this post) with $k=n\,/\,2$, for any $n$. I found them using Tad's recipe of repeatedly maximizing the determinant of $AA^\top$ by hill climbing and testing the candidate with the highest determinant among several runs. The determinants are

$$ 87546852131623099566361867104\;,\\ 93001686149176479553585114299\;. $$

I only had to test half a dozen candidates to find these two solutions, which seems consistent with $f(50)\simeq 22.4$. I'll now be testing these two with $24$ weighings; that will take the better part of a day and will require a bit more than a trillion difference vectors to be checked in each case.


I believe the bounty should go to Tad, who developed the mathematical approach. I tried to improve on it but couldn't, so instead I coded it a whole lot faster :-). Here's the code. It uses a special bit encoding for efficient arithmetic with vectors over $\mathbb F_3$. On my MacBook, it takes half a minute to test a candidate with $31$ weighings and two hours for a candidate with $26$ weighings.

The best solution it's found so far is $01010111100010011111110000111011000101101100100001$, with $26$ weighings required. I'm now looking for solutions with $25$ weighings, but that requires up to six hours of testing per candidate. I expect the minimum to be near $23$ (see below). I haven't implemented Tad's determinant maximization approach yet; the above solution was just the third candidate I tried with uniform sampling among the vectors (uniform sampling among the rotational equivalence classes would be worse since it gives higher weight to periodic sequences).

Here's a short summary of the mathematical basis of the code, mostly following Tad's ideas and notation; $n$ is the number of coins, and $k$ is the number of weighings. We can treat the two weights of the coins as $0$ and $1$. Then every possible weight configuration is characterized by a binary weight vector, and the differences between weight vectors are ternary vectors with entries $-1$, $0$ and $+1$. A solution is admissible if the $k\times n$ matrix $A$, with entries $A_{ij}\in\{0,1\}$ according as coin $j$ is weighed in weighing $i$, has different products with all possible weight vectors, or equivalently, if its product with all possible difference vectors is non-zero.

We can regard the difference vectors as vectors over $\mathbb F_3$. Only the difference vectors in the kernel of $A$ over $\mathbb F_3$ can be in the kernel of $A$ over $\mathbb Z$. The kernel over $\mathbb F_3$ will generally contain $3^{n-k}$ difference vectors, and these we have to check over $\mathbb Z$ (actually only half of them, due to invariance under negation). The key to doing this efficiently is to bit-encode $\mathbb F_3$ such that the time-limiting steps (addition, componentwise multiplication and summation of vectors) can be performed compactly using integer operations and table lookups instead of iterating over $n$ vector components.

Here are some results that expand on Tad's results for values well below $50$. $n_\text{c}$ is the number of equivalence classes under rotation; the numbers in the header row are $n-k$, and the numbers in the bodies of the two tables are the numbers and fractions, respectively, of rotational equivalence classes that yield a solution.

\begin{array}{c|c|cc} n_\text{c}&n&0&1&2&3&4&5&6&7&8&9\\\hline 2&1&1\\ 3&2&1\\ 4&3&2\\ 6&4&2&1\\ 8&5&6&3\\ 14&6&6&4\\ 20&7&18&12\\ 36&8&20&17&8\\ 60&9&50&45&25&6\\ 108&10&74&71&56&17\\ 188&11&186&178&130&83&4\\ 352&12&216&214&200&135&42\\ 632&13&630&614&520&469&261&6\\ 1182&14&916&910&878&787&535&101\\ 2192&15&2002&1988&1924&1831&1427&648&22\\ 4116&16&3040&3037&3000&2926&2605&1686&330&2\\ 7712&17&7710&7699&7464&7330&6915&5361&2131&34\\ 14602&18&10806&10801&10760&10649&10310&9014&5547&875\\ 27596&19&27594&27582&27270&27110&26565&24773&18964&7307&152\\ 52488&20&40642&40639&40592&40474&40024&38487&33414&20254&3102&2\\ 99880&21&94658&94640&94440&94281&93518&91759&85546&65010&24368&508\\ \end{array}

\begin{array}{c|c|cc} n_\text{c}&n&0&1&2&3&4&5&6&7&8&9\\\hline 2&1&.5000\\ 3&2&.3333\\ 4&3&.5000\\ 6&4&.3333&.1667\\ 8&5&.7500&.3750\\ 14&6&.4286&.2857\\ 20&7&.9000&.6000\\ 36&8&.5556&.4722&.2222\\ 60&9&.8333&.7500&.4167&.1000\\ 108&10&.6852&.6574&.5185&.1574\\ 188&11&.9894&.9468&.6915&.4415&.0213\\ 352&12&.6136&.6080&.5682&.3835&.1193\\ 632&13&.9968&.9715&.8228&.7421&.4130&.0095\\ 1182&14&.7750&.7699&.7428&.6658&.4526&.0854\\ 2192&15&.9133&.9069&.8777&.8353&.6510&.2956&.0100\\ 4116&16&.7386&.7379&.7289&.7109&.6329&.4096&.0802&.0005\\ 7712&17&.9997&.9983&.9678&.9505&.8967&.6952&.2763&.0044\\ 14602&18&.7400&.7397&.7369&.7293&.7061&.6173&.3799&.0599\\ 27596&19&.9999&.9995&.9882&.9824&.9626&.8977&.6872&.2648&.0055\\ 52488&20&.7743&.7743&.7734&.7711&.7625&.7333&.6366&.3859&.0591&.0000\\ 99880&21&.9477&.9475&.9455&.9439&.9363&.9187&.8565&.6509&.2440&.0051\\ \end{array}

Here are the minimal $k$ values up to $n=26$ (denoted by $f(n)$ as in Tad's table), together with the numbers and fractions of solution classes at minimal $k$:

\begin{array}{c|c|c|c} n&f(n)&\#&\#\,/\,n_\text{c}\\\hline 1&1&1&.5000\\ 2&2&1&.3333\\ 3&3&2&.5000\\ 4&3&1&.1667\\ 5&4&3&.3750\\ 6&5&4&.2857\\ 7&6&12&.6000\\ 8&6&8&.2222\\ 9&6&6&.1000\\ 10&7&17&.1574\\ 11&7&4&.0213\\ 12&8&42&.1193\\ 13&8&6&.0095\\ 14&9&101&.0854\\ 15&9&22&.0100\\ 16&9&2&.0005\\ 17&10&34&.0044\\ 18&11&875&.0599\\ 19&11&152&.0055\\ 20&11&2&.0000\\ 21&12&508&.0051\\ 22&12&8&.0000\\ 23&13&2340&.0064\\ 24&13&36&.0001\\ 25&14&10688&.0080\\ 26&14&216&.0001 \end{array}

The solution class counts of $2$ for $n=16$ and $n=20$ that both come at the end of an unusual triple of identical values of $f(n)$ are salient; here are the solution vectors:

$$ 0000101110111011\;,\\ 0000110111011101\;,\\ 00000101111011110111\;,\\ 00000111011110111101\;.\\ $$

Note that in both cases the two solutions are related by inversion, they contain slightly longer runs of $0$s than of $1$s, and the runs of $1$s are separate by single zeros.

It's tempting to speculate that the bound $f(n)\gt n/2$ that holds up to $n=26$ will continue to hold for higher $n$. However, I don't believe that this is the case. There's already a slight indication of this in the data; the solutions are gradually encroaching on the bound. (The trends in the absolute numbers are relevant here, not in the fractions, since we only need a single solution.) The fact that the third uniformly randomly guessed candidate turned out to be a solution for $k=26$, $n=50$ also points in this direction, since it suggests that the density of solutions at that point is much higher than it is for $k=n/2-1$ at lower $n$ values (where it's almost negligible).

Moreover, statistical considerations suggest that the asymptotic behaviour of $k$ might be $n\,/\log n$. There are various handwaving arguments that could be used to support this, based on entropy or collision probabilities; the details may be hard to get right, but the bigger picture is the same in each case: The $k$ measurements each have an effective space of order some power $n^\alpha$ to spread across ($\sqrt n$ if we consider them to be binomially distributed), so our discerning ability grows with $n^{\alpha k}$, while the number of possibilities we need to be able to discern grows with $2^n$; equating the logarithms yields $\alpha k\log n=n\log2$ and thus $k\propto n\,/\log n$.

Such $n\,/\log n$ behaviour seems consistent with the data up to $n=26$, so we can get a rough estimate e.g. from $f(26)=14$:

$$f(50)\simeq\frac{50\log26}{26\log50}\,f(26)\simeq1.6\,f(26)\simeq22.4\;.$$

That leaves ample space for improvement. :-)

joriki
  • 238,052
  • This is a wonderful answer and I feel at some point should be used to advertise math.stackexchange itself ! I will follow your generous advice and award the bounty to Tad unless someone comes up with a new idea before the bounty ends... and award the win to you when you find a solution with $k <n/2$. Does that sound reasonable? –  Jul 06 '15 at 08:21
  • I also have a closely related follow up puzzle which you should be able to use much the same machinery for... except it might be a little harder :) I won't post it for a few days though. –  Jul 06 '15 at 08:22
  • @Lembik: It certainly sounds reasonable. Note, though, that the current results satisfy $k\gt n/2$ without exception, so $k=n/2$ would already be somewhat significant. – joriki Jul 06 '15 at 08:31
  • 1
    I agree completely about $k=n/2$. Let me change my acceptance criterion to that. –  Jul 06 '15 at 08:34
  • 1
    @Lembik: Progress report: I implemented Tad's hill climbing for $\det AA^T$, and the four tests that I'm running with high-determinant patterns (in parallel on a quad-core processor) are all succeeding so far -- so we may well have a $k=25$ solution in six hours... – joriki Jul 06 '15 at 09:29
  • Which Java library are you using for import algebra.Matrix; ? (Thank you for releasing your code.) –  Jul 06 '15 at 11:40
  • @Lembik: It's all my own code -- sorry the gist isn't self-contained -- if you'd like to run it, I can make the classes it depends on available. – joriki Jul 06 '15 at 11:42
  • 1
    @Lembik: I put the entire code on github: https://github.com/joriki/algebra. It should be self-contained in that form. Please let me know if there are problems compiling or running it or if you have suggestions for improving it. – joriki Jul 06 '15 at 13:02
  • @Lembik: P.S.: The code in the algebra package is written with an eye to mathematical structures and not to efficient computation. It's only used for things that aren't costly, like computing a basis for the kernel. The time-consuming complete traversal of the kernel is done by code optimized for speed that doesn't use the algebra package. – joriki Jul 06 '15 at 13:07
  • 1
    @Lembik: P.P.S.: I forgot to mention: There's a slightly different version of Question1341400.java in that repository because I had to move a class in the process. I also added a main method to show how to use the code. You'll need to use that version and ignore the first one in the gist. – joriki Jul 06 '15 at 13:17
  • @Lembik: Unfortunately the four tests for $k=25$ all failed eventually. Some quite late, so I still think there should be solutions with $k=25$, but I won't be finding one before tonight. So the bounty goes to the one who deserves it... – joriki Jul 06 '15 at 15:02
  • @joriki Could http://aws.amazon.com/free/ help? –  Jul 06 '15 at 16:41
  • 2
    @Joriki: Great exposition! +1 for you and Tad of course. I'm pretty sure there is also a strong connection with coding theory especially error detecting codes. It would be nice to also find a thread in this direction. – Markus Scheuer Jul 07 '15 at 05:55
  • 1
    Welcome back... – draks ... Jul 09 '15 at 10:22
  • I put some interesting histograms about the $AA^T$ heuristic in the comments on the follow up question. It's still unclear to me exactly what is going on with it. –  Jul 09 '15 at 19:56
5

The following pattern works with $31$ weighings: $${0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, \ 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, \ 0, 1, 1, 1}.$$ This beats the $35$-weighing solution found earlier. $${1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, \ 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, \ 0, 0, 0, 1}.$$ See the comments at the end of this post.

This is not a complete answer, but it won't fit in a comment. We define $f(n)$ to be the smallest number of weighings possible for $n$ coins. Here is some simple but not particularly efficient Mathematica code which computes $f(n)$ for small $n$ by brute force: pick a representative $x$ of a rotational equivalence class of $n$-long $\{0,1\}$-vectors, build a matrix out of $k$ successive rotations of $x$, hit that matrix against all $\{0,1\}$-vectors, and see if all $2^n$ results are distinct. There are roughly $2^n/n$ rotation classes, so the complexity of this is about $4^n/n$.

(* check if vector x works when rotated k times *)
ok[x_, k_] := Block[{n = Length[x], m, v},
  m = RotateRight[x, #] & /@ Range[k];
  v = Tuples[{0, 1}, n];
  Unequal @@ (m.# & /@ v)];

(* compute a canonical representative for the rotation class of x *)
MinRotation[x_] := 
  First[Sort[RotateRight[x, #] & /@ Range[Length[x]]]];

f[n_] := f[n] = Block[{k, v},
  v = Select[Tuples[{0, 1}, n], # == MinRotation[#] &];
  For[k = 1, k <= n, k++,
  s = Select[v, ok[#, k] &];
  If[s != {}, Return[{k, First[s], Length[s]}]]]];

TableForm[Prepend[f[#], #] & /@ Range[12],
  TableDirections -> {Column, Row, Row},
  TableHeadings -> {None, {"n", "f(n)", "Example", "# of examples"}}]

$$ \begin{array}{cccc} \text{n} & \text{f(n)} & \text{Example} & \text{$\#$ of examples} \\ 1 & 1 & (1) & 1 \\ 2 & 2 & (0 1) & 1 \\ 3 & 3 & (0 0 1) & 2 \\ 4 & 3 & (0 1 1 1) & 1 \\ 5 & 4 & (0 0 1 1 1) & 3 \\ 6 & 5 & (0 0 1 0 1 1) & 4 \\ 7 & 6 & (0 0 0 0 1 1 1 & 12 \\ 8 & 6 & (0 0 0 1 0 1 0 1) & 8 \\ 9 & 6 & (0 0 1 0 0 1 0 1 1) & 6 \\ 10 & 7 & (0 0 0 0 1 1 0 1 1 1) & 17 \\ 11 & 7 & (0 0 0 1 0 1 0 0 1 1 1) & 4 \\ 12 & 8 & (0 0 0 0 1 0 0 0 1 0 1 1) & 42 \\ \end{array}$$

This quickly becomes infeasible. However, checking a given vector costs "only" $2^n$ matrix multiplies, so we can get some upper bounds for $f(n)$ by guessing good vectors $x$. A reasonable heuristic is that the $k\times n$ matrix $A$ we're constructing should have $\det A A^T$ large; using that, we find for example that $f(15)\le 9$, since $$(0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1)$$ turns out to work with $9$ rotations.

(Added 7/3/2015:) To construct the solutions for $k=31$ and $k=35$ weighings of $n=50$ coins, I started by running a hill-climb about $3$ times, and picked the pattern giving the largest $\det AA^T$. As a first check, I looked at a reduced basis for $\ker A$ to check that it didn't have any nonzero vectors whose coordinates were at most $1$ in absolute value, and then exhaustively checked $\ker A$ by putting it into Hermite form first. This requires checking about $(2/3)3^{n-k}$ vectors, which is easy on a laptop. The run for $k=31$ took about $7$ hours, $81$ times as long as the run for $k=35$.

Incidentally, just from a visual examination of the reduced bases for smaller values of $k$, I suspect that $f(50)$ is about $28$.

Tad
  • 6,679
  • Your heuristic is very interesting! If you plot $AA^T$ for all the weighings you tested for $n=12$, $f(n)=8$ do you see the ones that work at the peak? –  Jul 02 '15 at 07:20
  • I mean the determinant of $AA^T$ of course. –  Jul 02 '15 at 07:53
  • No, I don't think there's a simple rule like that -- the condition here is a very subtle combinatorial condition. Here's the deal: having two sets of coins which give the same output values is equivalent to having a nonzero vector $v$, with only $-1$'s, $0$'s and $1$'s, such that $vA=0$. On the other hand, Minkowski's theorem basically says that if $\det AA^T$ is small, then $\ker A$.will have short vectors. So you get a heuristic, not a guarantee; $\det AA^T$ can be large but $\ker A$ still has short vectors. It ultimately depends on more geometric details than just the determinant. – Tad Jul 02 '15 at 11:46
  • @Tad Could you explain why the length of the vectors in the kernel of $A$ is the relevant factor? I am probably missing something obvious. –  Jul 02 '15 at 13:45
  • If two vectors $v$ and $w$ of coins ($10$'s and $20$'s) give the same weights, then $Av=Aw$, i.e. $v-w\in\ker A$. So $(v-w)/10$ is also in $\ker A$, and all components of this vector are in ${-1,0,1}$. The converse also holds -- given such a vector in $\ker A$, you can find two sets of coins giving the same weights. (Looks like I may have transposed a matrix in my earlier comment; maybe that's the confusion. Sorry!) – Tad Jul 03 '15 at 03:12
  • @Tad Thank you but that was the part I understood! The part I didn't follow was your comment about "short vectors". Some vectors in ${-1,0,1}^n$ are long and some are short. You seemed to imply that if the kernel of $A$ only has short vectors then we know something about whether it is a solution or not. –  Jul 03 '15 at 06:12
  • I meant that all the vectors in ${-1,0,1}^n$ are short, compared to a "random" vector in $\ker A$, whose coordinates are not in general bounded by anything in particular. – Tad Jul 03 '15 at 12:33
  • @Tad Oh I see thank you! And sorry for my confusion. –  Jul 03 '15 at 12:46
  • Your method for finding solutions is very impressive. –  Jul 03 '15 at 20:58
  • Given a set of weighting result in the solution of 31, how lpng does it takes to determine the individual weights? – san Jul 05 '15 at 19:13
  • @san Excellent question. This situation is completely analogous to the phenomenon in coding theory that it is one thing to construct a code with a given error-correction capacity; it is another thing entirely to construct a code which can be efficiently decoded. I can guarantee that the given pattern allows the individual weights to be determined in principle, but the determination of weights may be computationally difficult. (You have to solve a linear system over the integers, with bounds; that problem is NP-hard in general.) Your solution is quite efficient in this respect. – Tad Jul 05 '15 at 19:34
  • That is what I thought. And how do I know that your solutions are correct? I have to trust you, which I do, but which is mathematically not very satisfying. If I now say the starting weighing (0,5,15,20,25) needs 35 weighings according to the rule to determine all the weights, how do you know if that is true?(It is true). – san Jul 06 '15 at 14:14
  • 2
    @san I think we can regard joriki's answers as computer aided proofs. You have to check the code that finds the answers. –  Jul 06 '15 at 16:17
  • 1
    @Tad: Very nice and instructive answer! +1 for you and Joriki – Markus Scheuer Jul 07 '15 at 06:06
  • 2
    Very nice comment with the bounty. I found a proof that $f(n) \geq 2n/\log_2{n}$ in Probabilistic methods in combinatorics. By Paul Erdös and Joel Spencer Academic Press, Inc., New York 1974 –  Jul 07 '15 at 06:17
  • @Lembik: In which section of the book did you find the proof? – joriki Jul 07 '15 at 06:52
  • @joriki "The kitchen sink", pages 100 and 101. This is a lower bound of $18$ for $n = 50$ so quite a lot lower than we are at now! –  Jul 07 '15 at 06:56
0

For $n\gt3$ the least number of weighings is $n-1$. All versions use the combinations of $n-1$ coins missing one, and a repeated weighing of the remaining coin.

If we analyse the original example, we can add up the total of the $3$ weighings. This gives us:

$2\times$(weight of coin $0$+weight of coin $1$+weight of coin $2$) $+3\times$weight of coin $3$. (I have used weights of $1$ and $2$ instead of $10$ and $20$.)

The sum of the first $3$ coins is from $\{3,4,5,6\}$ and so may take the values $\{6,8,10,12\}$, and the final coin provides either $3$ or $6$, giving the final set of possible weighings as $\{9,11,13,15,12,14,16,18\}$, or sorted: $\{9,11,12,13,14,15,16,18\}$.

So we take the $3$ weighings and add up the totals. Now because we have an even number of the first $3$ coins, we can determine the weight of the last coin as odd or even. This value can be removed from the original equations giving $3$ equations in $3$ unknowns, which have a solution.

For example if our three weighings give $5,5,6$, the totals weight is $16$. If the final coin weighed $1$, we would have $2\times(c_0+c_1+c_2)=13$, which is impossible. We infer the final coin must weigh $2$, so we have:

$$ c_0+c_1=3$$ $$ c_0+c_2=3$$ $$ c_1+c_2=4$$

which has the unique solution $c_0=1, c_1=2, c2=2$.

To generalize this, we can see that a solution set comes from:

$$(n-2)\{n-1,\dots,2n-2\}+(n-1)\{1,2\}$$

A possible weighing is unique modular $(n-2)$, and so we can determine the weight of the last coin by leaving a total weighing $0\mod(n-2)$, which leaves $(n-1)$ equations in $~(n-1)$ unknowns, which has a unique solution.

For example, with $5$ coins, we have the possible weights $\{4,5,6,7,8\}$ from the $4$ coins, and the total weighing is $3\times(c_0+c_1+c_2+c_3)+4\times c_4$. So the final total weighing will be either $3k+1$ or $3k+2$, telling us the value of $c_4$.

Because the range of coin wieghts is limited, a solution with more coins can often be achieved with less weighings than this. The variables are the number of coins used in weighings, the number of weighings and the possible weights of the coins.

JMP
  • 21,771
  • 1
    For 9 coins it seems we only need 6 weighings. Include coins 2, 5, 7 and 8 in the first weighing (indexing from 0). –  Jul 01 '15 at 06:32
  • @Lembik; ok i can see what you mean now!, i changed the last para, so this i suppose isn't a solution, but i think the maths is ok and on the right track.. – JMP Jul 02 '15 at 04:13
  • @JonMarkPerry If you assume $x_i=i$, then your solution is correct, although it is easier to start weighting $1,2,3$ and then make $n-1$ weighting according to the rule. – san Jul 02 '15 at 14:49