aspose file tools*
The moose likes Programming Diversions and the fly likes six coins Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "six coins" Watch "six coins" New topic
Author

six coins

Arjun Shastry
Ranch Hand

Joined: Mar 13, 2003
Posts: 1874
There are 6 coins. Two are counterfeit and are lighter than genuine ones.In 3 weighings, you need to find counterfeit coins.


MH
Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 509
I think question is open ended and allows to speculate.

There are six coins with 2 lighter coins. Considering 2gm as genuine and 1gm as counterfeit. 2,2,2,2,1,1

Divide them into two groups and weigh them. Two possibilities
1) They weigh unequal i.e. one group is heavier than other.
2) They weigh equal. A) 2,2,1 B) 2,2,1

First let's consider case 1 and groups were A1) 2,2,2 and B1) 2,1,1.

Now pick one coin from group A1 and mix with group B1 and again divide them in two groups.

Same possibility again,

1) They weigh unequal 2) They weigh equal

Consider they weigh unequal, A2) 2,2 B2) 1,1

The lighter group contains those two lighter coins.

Now, if you consider the second case i.e they weigh equal. A21) 1,2 B21) 1,2

Now, swipe two coins. There are two possibilities here You swipe 1)equally weighing 1 with 1 or 2 with 2 2) Unequally weighing 1 with 2 or 2 with 1

1) If you swipe unequally weighing coins and then weigh again you would find the lighter side as those two lighter coins. This is in 3 weighs only, but
2) If you swipe equally weighing coins then , you need to remember those two coins and separate them out and weigh with another two coins , and the lighter side is two lighter coins. This take 4 weighing.

I am leaving rest of the cases as homework.

(Did I take correct route?)





fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11499
    
  16



if you weigh 3 against three, and one side is lighter, you only need two weighings.

Both of the fake coins are in the lighter side.

take two from that side, and weigh them against each other. If they are equal, then those are the two counterfeit coins.

If they are unequal, the lighter one is counterfeit, as is the third, unweighed one.

[edit - corrected typo]


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 509
Saurabh Pillai wrote:(Did I take correct route?)


After looking at Fred's answer I did take wrong route. Thanks Fred.
kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1382
if you weigh 3 against three, and one side is lighter, you only need two weighings.

Both of the fake coins are in the lighter side.


If one fake coin is one side and another fake coin is another side during my first weighing
like (2 original coins + 1 fake coin one side and 2 original coins + 1 fake coin another side).
Then can we start from begining ?
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
kri shan wrote:If one fake coin is one side and another fake coin is another side during my first weighing
like (2 original coins + 1 fake coin one side and 2 original coins + 1 fake coin another side).
Then can we start from begining ?

No need. Because the first weighing balances, you now know that there exactly one counterfeit on each side. There is a way to find both of these, using just two weighings.
Arjun Shastry
Ranch Hand

Joined: Mar 13, 2003
Posts: 1874
Thanks all.My approach was- coins A,B,C,D,E,F(Lighter coins need not be of same weight).
First compare A---B--If they weigh same, then C and D. If they too weigh same, then compare A and C.If A and C are same, then E and F are lighetr coins.
if A and B don't weigh same, then its simple.
Henrique Ordine
Ranch Hand

Joined: Sep 03, 2004
Posts: 127
That's a lot more than 3 weighings.


J2EE Architect/Developer
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1027
Henrique Ordine wrote:That's a lot more than 3 weighings.

Oh really?

1: A-B
2: C-D

If we have identified two coins as lighter, we are done (e.g. A<B and C<D).

If we have identified one coin as lighter
3: E-F to find the 'other" lighter coin.

Otherwise (all scales balanced to date):
3: A-C

If balanced, then the two 'lighter' coins are E,F
If A<C, then the coins are A,B
otherwise the coins are C,D

That is only 3 weighings
Henrique Ordine
Ranch Hand

Joined: Sep 03, 2004
Posts: 127
Nice try.

1:A
2:B
3:C
4

I stopped counting after that.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19070
    
  40

Henrique Ordine wrote:Nice try.

I stopped counting after that.


Don't know what you mean. The solution looks like at most 3 weighings to me.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
Henrique Ordine wrote:Nice try.

1:A
2:B
3:C
4

I stopped counting after that.

Henrique: I think you're imagining a "weighing" differently than we are. That's probably because most of us have read similar problems to this, and we are assuming a detail which was not actually specified: the weighings are performed with a balance, in which you put as many things as you want on one side, and as many as you want on the other, and then you find out which side is heavier. (Or perhaps they balance, being equally heavy.) That's one weighing.
Henrique Ordine
Ranch Hand

Joined: Sep 03, 2004
Posts: 127
Oh, thát kind of balance. Yes, makes sense, sorry about that.
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1013
    
    3
Here's a twist on this puzzle: Can you come up with three predetermined weighings that will lead to the answer? i.e. You don't get to use the results of one weighing to determine which coins to weigh next.

I don't know if there is a solution, but how hard can it be?
Henrique Ordine
Ranch Hand

Joined: Sep 03, 2004
Posts: 127
I still have doubts about the last solution to the previous problem.

Are they assuming that if A<B then A is one of the lighter coins and B is not? If so, they said that the lighter coins don't necessarily need to have the same weight, so how do you know that they're not both the lighter coins. <br /> <br /> Also, are they assuming that if then they must be both original coins? If so, how do they know that they're not both lighter coins that coincidentally weigh the same weight?>
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1013
    
    3
Henrique Ordine wrote:I still have doubts about the last solution to the previous problem.

Are they assuming that if A<B then A is one of the lighter coins and B is not? If so, they said that the lighter coins don't necessarily need to have the same weight, so how do you know that they're not both the lighter coins. <br /> <br /> Also, are they assuming that if then they must be both original coins? If so, how do they know that they're not both lighter coins that coincidentally weigh the same weight?>


Yes, I do believe that even though it wasn't in the original problem statement we are assuming that both counterfeit coins are light by the same amount. Therefore, is A<B then A must be counterfeit and B must be real. <br /> <br /> >
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
No, Arjun's solution does not require the assumption that both counterfeits have the same weight.

If A < B, A is definitely counterfeit, and B is unknown.

From Stefan's description:
1: A-B
2: C-D

If we have identified two coins as lighter, we are done (e.g. A < B and C < D).

Meaning if both weighings are unbalanced, we have definitely identified two lighter coins, and those are the two counterfeits.

If we have identified one coin as lighter
3: E-F to find the 'other" lighter coin.

What was unstated here is that if E-F balance, that means that the second counterfeit must be in the first four. If only one of those two weighings was unbalanced, then the second counterfeit must be the heavier coin there. It was the coin we weren't sure about at first - now we know it must be counterfeit.

Otherwise (all scales balanced to date):
3: A-C

If balanced, then the two 'lighter' coins are E,F
If A<C, then the coins are A,B
otherwise the coins are C,D

This part works as stated.
anirudh jagithyala
Ranch Hand

Joined: Dec 07, 2010
Posts: 41
I analysed all possible ways and came up withe following logic

For every time we weigh we have 3 possible outcomes either equals, greater than or less than


consider the four coins as a,b,c,d,e,f
make three groups of two each say ab,cd,ef

Now there are two possibilities both the defective are in same group or the defectives are in different groups.


i gave all symbols in small letters ,, sorry for that.......


as there are 2 fake coins in 6 coins these can have (6*5)/2=15 outcomes {Permutations and combinations}
I tried to get all the combination of 15 outcomes with the above analyses........

Hope this helps...


Eugene Rabii
Ranch Hand

Joined: Apr 24, 2009
Posts: 30
That was simpler then I first read it But still fun.

1. A and B, then C and D and then... well yes it get obvious really fast.

Cheers,
Eugene.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: six coins