[CrackMonkey] [schoen@loyalty.org: Pill-weighing]
Seth David Schoen
schoen at loyalty.org
Sun Feb 13 19:26:28 PST 2000
Mr. Bad writes:
> >>>>> "SDS" == Seth David Schoen <schoen at loyalty.org> writes:
>
> SDS> You are a pharmacist, and [...]
>
> SDS> (1) You have n bottles of pills. Each bottle contains an
> SDS> unknown number of pills. The pills are supposed to be 100
> SDS> mg, but one bottle is "bad": all the pills in that bottle are
> SDS> 101 mg instead.
>
> SDS> By using a scale only once, how can you immediately tell
> SDS> which bottle is bad?
>
> OK, I think I have a partial solution to this one. Let's say you
> number the bottles from 1 to N. You put on the scale 1 pill from
> bottle 1, 2 pills from bottle 2, 3 pills from bottle 3, etc.
Right.
> Then, you get a weight result. The result will be something like
> 602. You can take the weight modulus 100 to find out the # of the
> bottle with the 101 mg. pills.
>
> This gets mucked up if you have 100 or more bottles, though.
Why are you doing mod 100? Why not just subtract 100*(n^2+n)/2?
> Another
> way you could do it is for bottle X, put 100 * (10 ^ ((X - 1) * 3)
> pills on. In other words, for bottle 1, put 100 pills on. For bottle
> 2, put 100,000 pills on. For bottle 3, put 100,000,000 pills on. Then
> you'll get a reading like 100101100. You can tell its the 2nd bottle
> that has the bad pills, because it's where the "101" shows up.
Right. Why are you doing this in base 10? Isn't that a little wasteful?
> SDS> (2) You have n bottles of pills. Each bottle contains an
> SDS> unknown number of pills. The pills are supposed to be 100
> SDS> mg, but some number of bottles (maybe none of them, maybe all
> SDS> of them, maybe some number in between!) are "bad": all the
> SDS> pills in those bottles (if any) are 101 mg instead.
>
> SDS> By using a scale only once, how can you immediately tell
> SDS> which bottles, if any, are bad?
>
> Hey, my second solution works for this, too! If you get an answer like
> 101,100,100,101 then your 4th and 1st bottles are "bad."
Right again. Why are you doing this in base 10? :-)
> ~Mr. Bad
>
> P.S. Now I see what you mean by "unrealistic"!
It would be a little more realistic if you didn't insist on base 10. :-)
--
Seth David Schoen <schoen at loyalty.org> | And do not say, I will study when I
Temp. http://www.loyalty.org/~schoen/ | have leisure; for perhaps you will
down: http://www.loyalty.org/ (CAF) | not have leisure. -- Pirke Avot 2:5
More information about the Crackmonkey
mailing list