# 12 Coins 3 weighings generalization [duplicate]

I know the famous 12 coin, 3 weighings problem has been asked a few times already. And I saw at least one solution which can be adapted to this problem. Here's a generalisation (one of the many which could be done of course).

Suppose you have 120 coins, all identical, except for 1 which is a slightly different weight. You have a pan balance, and need to make as few weighings as possible to identify both (a) which coin is counterfeit, and (b) whether it's heavier or lighter. There's no cheating, like adding coins on half way (weigh?) through - that would be an additional weighing.

The answer may surprise some people. I would like to know:

• How many weighings are needed, and
• A reasonable strategy for doing this

A common solution to the 12 coin puzzle involves...I can barely type the word...cases (gasp)! That would get tricky for 120 coins, but you are, of course, most welcome to do so! I can't promise to read through all the cases and mark it right though.

• I'm not quite sure what kind of solution you expect. The extension of a well known solution to 120 coins, which you don't want to read? – Sleafar Sep 12 '15 at 18:36
• My concern is with cases. The solutions that use cases are long, even for the 12 coin puzzle. But other strategies exist... – Dr Xorile Sep 12 '15 at 18:38
• You mean something like the 2nd answer here: puzzling.stackexchange.com/questions/183/… ? – Sleafar Sep 12 '15 at 18:52
• Exactly! The 1st answer uses cases, but the second is more easily generalizable. – Dr Xorile Sep 12 '15 at 18:58
• Specifically, look at my accepted answer at the bottom if you want a strategy that doesn't use cases. – Joe Z. Sep 13 '15 at 2:51

First, number the coins using Balanced Ternary. This is a ternary numeral system using the digits -, 0, and + to represent -1, 0, and 1.

For the sake of brevity I'm going to illustrate this using 12 coins, but this can be easily extended to larger numbers. Just add more trits to each number. (For example, 120 coins would require 5 trits, corresponding to 5 weighings.)

• 1 = 00+
• 2 = 0+-
• 3 = 0+0
• ...
• 11 = ++-
• 12 = ++0

Each of these can also be inverted by swapping each symbol.

• -1 = 00-
• -2 = 0-+
• -3 = 0-0
• ...

This numbering now tells us where to place the coins.

For the first weighing, put all the coins with a + in their first trit on the right pan, and all the coins with a - in their first trit in the left pan. Leave all the coins with a 0 in their first trit off. Then record the result: if it tips to the left, that's a -. If it tips to the right, that's a +. If it is balanced, that's a 0.

Repeat as many times as necessary, then look at the number you've recorded. With 12 coins there will be three weighings, so the result might be e.g. +-+ (tipped to the right, tipped to the left, tipped to the right). This is the number of the false coin. If it's positive, that coin is heavier. If it's negative, that coin is lighter. If the number is zero, no coin was fake.

HOWEVER, this doesn't actually work precisely as I have written it. No positive number has a - in its first trit, so the first weighing will have one pan empty. Unless you have a stock of real coins to compare against (a variant of the problem), it won't be a useful measurement.

So we need to invert some of the coins' numbers (so coin 5 might become coin -5), then interpret the result differently if one of these is chosen: a negative number will now mean that the fake coin is heavier, and a positive number that it is lighter.

This is where I got stuck in my own experimentation, but some web research indicates that John Conway came up with a very clever way to determine which ones to flip: go through the coins, and look at the first "change" in the sequence. If it is - to 0, or 0 to +, or + to -, keep it positive. Otherwise, invert that number.

This isn't as elegant as I would like—it feels like there should be some way to decide mathematically which numbers to invert. But for now, that solution is the best I have.

Each weighing allows you to triple the number of coins, so you should be able to do 36 coins in four weighings, 108 in five, but require six for 121 coins. The solution for 12 coins only gets complex for the endgame. For 108, you split them into three batches of 36 and weigh two batches. If they balance, you are down to the 36 case. If not, you have 36 H coins (which might be heavy) and 36 L coins (which might be light). Weigh 12H+12L against 12H+12L. No matter the result, you now have 12H+12L and can weigh 4H+4L against 4H+4L. No matter the result, you are in the 12 coin case where the first weighing did not balance.

• This is not quite right – Dr Xorile Sep 13 '15 at 14:04
{"ft_lang_label":"__label__en","ft_lang_prob":0.94855887,"math_prob":0.9441756,"size":2322,"snap":"2021-21-2021-25","text_gpt3_token_len":603,"char_repetition_ratio":0.13201036,"word_repetition_ratio":0.0064794817,"special_character_ratio":0.27906978,"punctuation_ratio":0.13779527,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98270506,"pos_list":[0,1,2],"im_url_duplicate_count":[null,4,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-05-07T23:14:22Z\",\"WARC-Record-ID\":\"<urn:uuid:2bd7b64a-ff2f-4bc4-b611-79a5a3d9484b>\",\"Content-Length\":\"162302\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:30808b5d-a1fb-4f3d-858f-cdd825106812>\",\"WARC-Concurrent-To\":\"<urn:uuid:95fcb13b-1db4-4ed2-872e-0d6ad3928bf6>\",\"WARC-IP-Address\":\"151.101.129.69\",\"WARC-Target-URI\":\"https://puzzling.stackexchange.com/questions/22132/12-coins-3-weighings-generalization\",\"WARC-Payload-Digest\":\"sha1:N5KLMGSLIKH77GQOP6X2DA4DZIGTNCPI\",\"WARC-Block-Digest\":\"sha1:WO6IML3CQBYBPHQBE2QPQNW55S2TZORX\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-21/CC-MAIN-2021-21_segments_1620243988828.76_warc_CC-MAIN-20210507211141-20210508001141-00312.warc.gz\"}"}