Defective Ball puzzle

39 balls problem:

You have 39 balls in front of you. All but one are of equal weight. You do not know whether the defective ball is lighter or heavier than the normal balls. You are given a comparison balance. You can use the balance only 4 times. How would you find out which is the defective ball? Is it heavier or lighter?

Number all balls from 1 to 39.

Case 1 :
{1-9,10-13}:{14-17,18-26} —— 1st weighing
which leads to two possible results
1.A.  balanced , meaning defective ball in (27-39)
1.B.  light:heavy(1-26 )  or

1.C heavy:light(1-26 ) which means one of 1-26 is defective.

For  case 1.A,
2nd weighing :
27-30:31-34
which once again it leads to two results
2.a.  balanced, meaning defective in (35-39)
2.b.  light:heavy or heavy:light(meaning defective in 27-34)
For 2.a,(B will be for later)
3rd weighing:
3 N balls :35,36,37 {N stands for normal balls}
which narrows down to two results
3.I. balanced(  defective in in 38,39)
3.II.unbalanced, 35-37 will either be H/L, take note of whether it is H/L

For 3.I,
4th weighing:
x:38—-balanced so 39 is defective
—-unbalanced then 38 and you know if it is H/L
For 3.II,
4th weighing:
35:36—balanced — 37 is defective
—unbalanced — 35/36 –if in the 3rd weighing, you know that the defective ball is H, then the H ball this time is defective; same with L.
For 2.b,
3rd weighing:
27,28,29,31:30,N,N,N
which leads to three cases
3.i.light:heavy(defective among 27-29, and the defective ball is L)
3.ii.heavy:light(defective among 30,31)
3.iii.balanced(defective 32-34, the defective is H)
For 3.i,4th: 27:28
For 3.ii, 4th: 30:N
For 3.iii, 4th: 32:33
(the rest is omitted for its simplicity, like previous deductions, you can determine which is defective)
Finally, we come to 1.B
2nd weighing:
1-9{L},14-17{H}:10-13{L},9N (—a total of 9 normal balls)
which leads to three more cases
‘.light:heavy(defective among   1-9, lighter)
”.heavy:light(defective among   10-17)
”’.balanced(defective among  18-26, heavier)
For’
3rd weighing:
1,2,3:4,5,6
if unbalanced, take the lighter set, then compare two of them to each other, either the lighter one is defective or the one that have not been weighed is.
if balanced, compare 7:8, the lighter one is defective.
For”’, it’s similar to ‘, just change ‘light’ to ‘heavy’ and the rest is the same.
For”
3rd weighing :
14{H},15{H},16{H},10{L}:17{H},N,N,N
if balanced —-  test 11,12,13 , all lighter

if light:heavy then test between 10{L} & 17 (H)

if heavy:light then test between 14,15 & 16 ,all heavier
—————————————————–
and that’s all, all the cases are covered, and you should be able to find out the defective ball.

Follow similar approach for all left out cases.

Given (N ) balls, one is defective and the rest N-1 can be genuine.

we need atleast k > log3(2N + 1) weighing to find the defective one

So for 40 balls , 5 weighing ‘s

for 39 balls , 4 weighing’s

for 12 balls , 3 weighing’s

for 13 balls , 4 weighing’s

12 Balls Problem

You are give 12 identical looking balls. One of them is fake (could be heavier or lighter) than the rest of the 11 (all the others weight exactly the same). You a provided with a simple mechanical balance and you are restricted to only 3 uses. Find the fake ball.

Name the balls 1-12.

First we weigh {1,2,3,4} on the left and {5,6,7,8} on the right. There are three scenarios which can arise from this.

If they balance, then we know 9, 10, 11 or 12 is fake. Weigh {8, 9} and {10, 11} (Note: 8 is not fake here )

If they balance, we know 12 is the fake one. Just weigh it with any other ball and figure out if it is lighter or heavier.

If {8, 9} is heavier, then either 9 is heavy or 10 is light or 11 is light. Weigh {10} and {11}. If they balance, 9 is fake (heavier). If they don’t balance then whichever one is lighter is fake (lighter).

If {8, 9} is lighter, then either 9 is light or 10 is heavy or 11 is heavy. Weigh {10} and {11}. If they balance, 9 is fake (lighter). If they don’t balance then whichever one is heavier is fake (heavier).

If {1,2,3,4} is heavier, we know either one of {1,2,3,4} heavier or one of {5,6,7,8} is lighter but it is guarantees that {9,10,11,12} are not fake. This is where it gets really tricky, watch carefully. Weigh {1,2,5} and {3,6,9} (Note: 9 is surely not fake).

If they balance, then either 4 is heavy or 7 is light or 8 is light. Following the last step from the previous case, we weigh {7} and {8}. If they balance, 4 is fake(heavier). If they don’t balance then whichever one is lighter is fake (lighter).

If {1,2,5} is heavier, then either 1 is heavy or 2 is heavy or 6 is light. Weigh {1} and {2}. If they balance, 6 is fake (lighter). If they don’t balance then whichever one is heavier is fake (heavier).

If {3,6,9} is heavier, then either 3 is heavy or 5 is light. Weigh {5} and {9}. They won’t balance. If {5} is lighter, 5 is fake (lighter). If they balance, 3 is fake (heavier).

If {5,6,7,8} is heavier, it is the same situation as if {1,2,3,4} was heavier. Just perform the same steps using 5,6,7 and 8. Unless maybe you are too lazy to try and reprocess the steps, then you continue reading the solution. Weigh {5,6,1} and {7,2,9} (Note: 9 is surely not fake).

If they balance, then either 8 is heavy or 3 is light or 4 is light. Following the last step from the previous case, we weigh {3} and {4}. If they balance, 8 is fake(heavier). If they don’t balance then whichever one is lighter is fake (lighter).

If {5,6,1} is heavier, then either 5 is heavy or 6 is heavy or 2 is light. Weigh {5} and {6}. If they balance, 2 is fake (lighter). If they don’t balance then whichever one is heavier is fake (heavier).

If {7,2,9} is heavier, then either 7 is heavy or 1 is light. Weigh {1} and {9}. If they balance, 7 is fake (heavier). If they don’t balance then 1 is fake (lighter).