File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programming Diversions and the fly likes find the heavier ball Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "find the heavier ball " Watch "find the heavier ball " New topic

find the heavier ball

rehans oberoi
Ranch Hand

Joined: Dec 06, 2005
Posts: 174
Suppose you had 8 billiard balls, and one of them was slightly heavier, but the only way to tell was by putting it on a scale against another. What's the fewest number of times you'd have to use the scale to find the heavier ball?
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Put 4 balls each in Pan A & Pan B find the pan having the heaviest ball. Let it be pan b. So all 4 balls in Pan A are good balls, keep it seperate.
Now group the balls in pan b into two sets 2 in each pan. Find the Pan having the heaviest ball Let it be Pan A. Now you have identified 6 good balls.

Take one ball from Pan A and weigh it against any one of the 6 good balls if both are equal then the other ball is the culprit else this one should be the culprit.
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

once. if i was lucky.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791

Put three on each side of the scale. If they match weigh the other two. If they don't match, weigh two of the heavy three.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Bert Bates

Joined: Oct 14, 2002
Posts: 8898
for extra credit, show how if you had 12 balls, and one was either lighter or heavier, you can find the odd ball with only three shots at the balance.

Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
I agree. Here's the link:
subject: find the heavier ball
It's not a secret anymore!