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?
The Solution
My original solution to this problem was this:
Binary search. Put all eight balls on the scale. Take four off. If they weigh more than half the weight of all eight leave those four on. If they weigh less than half the weight of all eight take those four off and put the other four on. Take two balls off. If the two weigh more than half the weight of the four balls leave them on. If the two weigh less than half the weight of the four balls take those two off and put the other two on. Take one ball off. If the one ball weighs more than half the weight of the two, the heaviest ball is on the scale. Otherwise it’s in your hand. The fewest number of times you have to use the scale is 4 (to get the weight of 8 balls, 4, 2 and then 1).
Terry Stoeckert, statistician friend of mine showed me a better way to do this. He also pointed out an error in my process.
First the error. I used two different kinds of scales. In the problem statement I refer to a balance scale. In the solution I refer to a weight-scale. Duh!
Terry’s solution was to stick with the balance scale and put three balls on each side, leave two balls off the scale.
If the two sides of the scale are equal in weight, take the six balls off the scale, take the two balls you left off the scale for the first weighing and put one on each side. Whichever side is heavier tells you which ball is heavier.
If one side was heavier than the other in the first weighing, clear the lighter side, take one ball off the heavier side and move it to the lighter side. Take another ball off the heavier side and hold it in your hand. If the two sides are equal in weight, then the heavier ball is in your hand. If one side is heavier than the other however, then the heavy ball is on the heavier side.
So, with Terry’s solution, the heavy ball can be found in two weighings. Nice work Terry.
I've got a masters degree in computer science and over 10 years of experience building web-based systems using Java/J2EE, Ruby, Rails and PHP. I'm a strong believer in the effectiveness of Agile Methods. Read more »
Eight Billiard Balls
The Problem
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?
The Solution
My original solution to this problem was this:
Binary search. Put all eight balls on the scale. Take four off. If they weigh more than half the weight of all eight leave those four on. If they weigh less than half the weight of all eight take those four off and put the other four on. Take two balls off. If the two weigh more than half the weight of the four balls leave them on. If the two weigh less than half the weight of the four balls take those two off and put the other two on. Take one ball off. If the one ball weighs more than half the weight of the two, the heaviest ball is on the scale. Otherwise it’s in your hand. The fewest number of times you have to use the scale is 4 (to get the weight of 8 balls, 4, 2 and then 1).
Terry Stoeckert, statistician friend of mine showed me a better way to do this. He also pointed out an error in my process.
First the error. I used two different kinds of scales. In the problem statement I refer to a balance scale. In the solution I refer to a weight-scale. Duh!
Terry’s solution was to stick with the balance scale and put three balls on each side, leave two balls off the scale.
If the two sides of the scale are equal in weight, take the six balls off the scale, take the two balls you left off the scale for the first weighing and put one on each side. Whichever side is heavier tells you which ball is heavier.
If one side was heavier than the other in the first weighing, clear the lighter side, take one ball off the heavier side and move it to the lighter side. Take another ball off the heavier side and hold it in your hand. If the two sides are equal in weight, then the heavier ball is in your hand. If one side is heavier than the other however, then the heavy ball is on the heavier side.
So, with Terry’s solution, the heavy ball can be found in two weighings. Nice work Terry.