[CrackMonkey] [schoen@loyalty.org: Pill-weighing]

Mr. Bad mr.bad at pigdog.org
Sun Feb 13 19:11:32 PST 2000


>>>>> "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.

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. 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. 

    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."

~Mr. Bad

P.S. Now I see what you mean by "unrealistic"!





More information about the Crackmonkey mailing list