Thursday, October 29, 2020

Find the Jar with contaminated pills

Problem: You have 5 jars of pills. Each pill weighs 10 grams, except for contaminated pills contained in one jar, where each pill weighs 9 grams. Given a scale, how could you tell which jar had the contaminated pills in just one measurement?

Solution: Take following number of pills from each jar:

  • Jar 1: 1 pill
  • Jar 2: 2 pills
  • Jar 3: 3 pills
  • Jar 4: 4 pills
  • Jar 5: 5 pills
Take the weight of all these 15 pills. Ideally if all the pills are of same weight i.e. 10 grams then the total weight should have been (10 X 15 =) 150 grams but we know that in one of the jar the pill weight is 9 grams i.e. 1 gram lesser than the usual pills. Let's see how it can impact this calculations:
  1. If Jar 1 has contaminated pills  then the total weight would be 1 X 1 = 1 gram lesser than 150 grams. That means if total weight is (150 - 1 =) 149 grams then we can say Jar 1 has contaminated pills.
  2. If Jar 2 has contaminated pills then the total weight would be 2 X 1 = 2 gram lesser than 150 grams. That means if total weight is (150 - 2 =) 148 grams then we can say Jar 2 has contaminated pills.
  3. With the same logic we can say:
    1. total weight is (150 - 3 =) 147 then answer is Jar 3
    2. total weight is (150 - 4 =) 146 then answer is Jar 4
    3. total weight is (150 - 5 =) 145 then answer is Jar 5
Problem solved 😀.

No comments:

Post a Comment