Sunday, December 11, 2011

Detect heavy/light ball (among 12 balls)

There are 12 balls that you have out of which one is the odd one out, which means it can be heavy/light. You have three chances to find the odd ball and also whether it's heavy or light.

Variant:
You are given 9 balls. Out of these, 8 are of 1kg and 1 is heavier by 0.5 kg. Given a weight balance which can take tell you which side is heavier at a given trial, you have to compute heavier ball by weighing only twice.

Strategy:
Divide 9 balls in groups of 3.
  • Compute the heavier group using balance by keeping two groups on it. If they come as equal, we can conclude third group contains the heavier ball.
  • After we have the group that contains the heavier ball, keep the two balls on the balance, you will get the heavier one. (In case, both are equally weighed, the left out will be the heavier one)

2 comments:

  1. Try weighing 8 weights to start with (4 on each side)...

    ReplyDelete
    Replies
    1. Take eight balls, and put four on one side of the scale, and four on the other.

      If the scale is balanced, that means the odd ball out is in the other 4 balls.
      Let's call these 4 balls O1, O2, O3, and O4.
      Take O1, O2, and O3 and put them on one side of the scale, and take 3 balls from the 8 "normal" balls that you originally weighed, and put them on the other side of the scale.
      If the O1, O2, and O3 balls are heavier, that means the odd ball out is among these, and is heavier. Weigh O1 and O2 against each other. If one of them is heavier than the other, this is the odd ball out, and it is heavier. Otherwise, O3 is the odd ball out, and it is heavier.
      If the O1, O2, and O3 balls are lighter, that means the odd ball out is among these, and is lighter. Weigh O1 and O2 against each other. If one of them is lighter than the other, this is the odd ball out, and it is lighter. Otherwise, O3 is the odd ball out, and it is lighter.
      If these two sets of 3 balls weigh the same amount, then O4 is the odd ball out. Weight it against one of the "normal" balls from the first weighing. If O4 is heavier, then it is heavier, if it's lighter, then it's lighter.
      If the scale isn't balanced, then the odd ball out is among these 8 balls.
      Let's call the four balls on the side of the scale that was heavier H1, H2, H3, and H4 ("H" for "maybe heavier").
      Let's call the four balls on the side of the scale that was lighter L1, L2, L3, and L4 ("L" for "maybe lighter").
      Let's also call each ball from the 4 in the original weighing that we know aren't the odd balls out "Normal" balls.
      So now weigh [H1, H2, L1] against [H3, L2, Normal].
      -If the [H1, H2, L1] side is heavier (and thus the [H3, L2, Normal] side is lighter), then this means that either H1 or H2 is the odd ball out and is heavier, or L2 is the odd ball out and is lighter.
      -So measure [H1, L2] against 2 of the "Normal" balls.
      -If [H1, L2] are heavier, then H1 is the odd ball out, and is heavier.
      -If [H1, L2] are lighter, then L2 is the odd ball out, and is lighter.
      -If the scale is balanced, then H2 is the odd ball out, and is heavier.
      -If the [H1, H2, L1] side is lighter (and thus the [H3, L2, Normal] side is heavier), then this means that either L1 is the odd ball out, and is lighter, or H3 is the odd ball out, and is heavier.
      -So measure L1 and H3 against two "normal" balls.
      -If the [L1, H3] side is lighter, then L1 is the odd ball out, and is lighter.
      -Otherwise, if the [L1, H3] side is heavier, then H3 is the odd ball out, and is heavier.
      If the [H1, H2, L1] side and the [H3, L2, Normal] side weigh the same, then we know that either H4 is the odd ball out, and is heavier, or one of L3 or L4 is the odd ball out, and is lighter.
      So weight [H4, L3] against two of the "Normal" balls.
      If the [H4, L3] side is heavier, then H4 is the odd ball out, and is heavier.
      If the [H4, L3] side is lighter, then L3 is the odd ball out, and is lighter.
      If the [H4, L3] side weighs the same as the [Normal, Normal] side, then L4 is the odd ball out, and is lighter.

      Delete