30 lines
1.6 KiB
Markdown
30 lines
1.6 KiB
Markdown
# 6.1. The heavy pill
|
|
|
|
> You have 20 bottles of pills. 19 bottles have 1.0 gram pills, but one has pills of weight 1.1 grams. Given a scale that provides an exact measurement, how would you find the heavy bottle? You can only use the scale once
|
|
|
|
To reduce the entropy, using one measurement we can get to 10 bottles. It'd take log(20) measurements to find the bottle.
|
|
|
|
## Hints
|
|
|
|
> You can only use the scale once. This means that all, or almost all, of the bottles must be used. They also must be handled in different ways or else you couldn't distinguish between them
|
|
|
|
Handled in different ways?
|
|
|
|
> What happens if you put one pill from each bottle on the scale? What if you put two pills from each bottle on the scale?
|
|
|
|
One pill from each bottle we get 19g + 1.1g = 20.1g. Two pills per bottle, 38g + 2.2g = 40.2g. But that still gives us no info as to which is the bottle.
|
|
|
|
> Imagine there were just three bottles and one had heavier pills. Suppose you put different numbers of pills from each bottle on the scale (for example, bottle 1 has 5 pills, bottle 2 has 2 pills, and bottle 3 has 9 pills). What would the scale show?
|
|
|
|
The scale depends on how many pills you put from each bottle. If we put 1 pill for bottle1, 2 for bottle2, 3 for bottle3
|
|
|
|
* if bottle1 is the heavy one: scale = 6.1
|
|
* if bottle2 is the heavy one: scale = 6.2
|
|
* if bottle3 is the heavy one: scale = 6.3
|
|
|
|
> You should be able to have an equation that tells you the heavy bottle based on the weight
|
|
|
|
`scale = sum(range(len(bottles))) + 0.1 * bottles.index(heavy + 1)`
|
|
|
|
We have the scale number and the bottle list, we solve for `heavy`. sum(range(len(bottles))) = 20 * 21 / 2 = 210.
|