Simplified Problem
I'm going to start with a slightly modified version of question 3, and then use the answer to that problem to answer the original questions.
The first problem to solve is:
You visit the store and find that all types of mice except for the small ones are sold out. Looks like your budget for testing 1000 batches isn’t enough, so you aim for 100 batches instead, what’s the minimum cost to identify the poisoned batch?
What’s the minimum cost to identify the poisoned batch?
We can solve this smaller problem with just a few mice, using the following method.
Number the batches 0 to 99
Mouse 1 tests batches with odd numbers (1,3,5,9)
Mouse 2 tests batches with numbers that become odd when divided by 2, rounding down (2-3, 6-7)
Mouse 3 tests batches with numbers that become odd when divided by 4, rounding down (4-7, 12-15)
Mouse 4 tests batches with numbers that become odd when divided by 8, rounding down (8-15,24-31)
Mouse 5 tests batches with numbers that become odd when divided by 16, rounding down (16-31,48-63)
Mouse 6 tests batches with numbers that become odd when divided by 32, rounding down (32-63,96-99)
Mouse 7 tests batches 64-99
This uses a total of 7 mice.
After midnight, we can then find which batch is poisoned by
Arranging the mice in descending order and interpreting the lineup as a binary number, where dead mice are 1 and live mice are 0. So if mice 3, 4, and 7 died, we read the number as 1001100 or 76, which is the only batch tested by exactly those three mice.
Problem 1
Moving on to the real question now.
What’s the minimum cost to identify the poisoned batch?
The final answer total will be
$45.50
We use the method described above, with two small modifications.
We run the method above three times, with larger mice.
Batches 0-400 can be tested by 9 large mice.
Batches 401-800 can be tested by another 9 large mice.
Batches 801-999 can be tested by 8 medium mice.
We can reduce the cost further by
Replacing the first mouse from each group with a mouse king, which will test all odd-numbered batches from all three groups.
This gives a final cost of
16 large mice, 7 medium mice, and one mouse king, which cost $45.50
But wait!
If the 0'th batch in one of the three groups is poisoned (batch 0, batch 400, or batch 800), none of the mice will die, and then we won't know which group contains the poison batch. Similarly, if the first batch in one group is poisoned, only the mouse king will die, who is shared between all groups.
We can solve this by having the last mice from each group eat the first two pills from each of the other two groups. Then, if mice from more than one group die, we know that the group where all mice survived contains the poison.
The medium mouse group's last mouse only has room for 3 more pills, and we need them to eat 4, so for that group, we'll also need to have the second-to-last mouse eat one extra pill.
Problem 2
If the mouse king is unavailable, but each medium mouse can consume 125 pills, what’s the minimum cost to identify the poisoned batch?
We use the method above to get this with a budget of
$48.00
The details:
We divide the batches into 4 groups of 250, each of which can be tested by 8 medium mice. 32 medium mice costs $48.00
Once again, we need to account for the 0's case.
Each group's last mouse also tests the groups immediately before and after it.
Problem 3
You visit the store and find that all types of mice except for the small ones are sold out. Looks like your budget for testing 1000 batches isn’t enough, so you aim for 500 batches instead, what’s the minimum cost to identify the poisoned batch?
The final cost will be
$35.00
Once again, we start with the same strategy, plus divide and conquer.
We could the batches into 5 groups of 100, each of which takes 7 small mice to test, spending $35.00 in total.
We can do very slightly better, using a trick we learned from the mouse king in problem 1.
The last mouse in each group tests only 35 batches, which totals to 175 batches to test. Instead of buying a separate mouse for each group, we can buy only 4 mice to test the lot, allowing this to be done with only 34 small mice in total.
There are a few edge cases left to account for
The zero'th batches of each group are all indistinguishable from one-another, and the 64th batch of each group is tested by only the final group of mice. Since there are 3 high-mice testing 5 groups, this necessarily means that there will be 2 pairs of groups whose 64th is tested by the same mouse. We will group these 7 batches together into one special group, and take the second-to-last mouse from each of the first three groups and have them test this special group, requiring them each to eat a maximum of 4 additional pills, (which they can - they only ate 36 pills each previously). We only need 3 mice to test 7 pills, because numbers 0-6 can be represented with only 3 binary digits. The second-to-last mouse of the final two groups will test the entire special group. If both of these mice die, we know to read the special group instead of the regular groups.
Problem 4
You call the boss about the situation that only small mice are left, and he gives you more budget but insists on testing all 1000 batches, what’s the minimum cost to identify the poisoned batch?
We can solve this exactly like problem 3, except the numbers work out a little more nicely. The total comes out to
$67.00
Start with a divide-and-conquer strategy
Split the batches into 10 groups of 100 batches each. Each group takes 7 mice to test, which would take 70 mice.
Once again, we can save money by fully utilizing each mouse.
There are 350 high pills (35 pills per group, times 10 groups) so we can remove one mouse from each group and replace them with 7 mice, for a total of 67 small mice in the end.
And once again, the edge cases.
This time, there are 10 zero'th batches, plus 3 more 64th batches which are pigeonholed out from being uniquely identified by the last rat group. We create a special group of 13 pills. Once again, we form a special group to test this. This time, the special group needs 4 mice to test it (since we need 4 bits to represent the number 13), and the mice testing it will need to consume up to 8 pills. The 6th mouse from each group can still handle this, since they have room for 14 more pills each.
We still need two signaling mice to indicate that the special group is active, who need to each eat 13 pills. Luckily, we still have 6 more mice with room, so we can choose any two of them to form the signal.
We should applaud our boss's insight in choosing to spend an extra $33 on tests instead of risking a 50% chance of throwing out 500 whole batches of medicine (or killing a patient).