The Poisoned Bottle
Description:
PLEASE RATE AND RANK THE KATA IF YOU SOLVED IT, TO HELP IT GET OUT OF BETA. THANKS!
This is a slightly more advanced version of this kata
Story
In a nut's shell: the King receives a number of bottles of wine, but he suspects that one of them is poisoned. Luckily, he has some lab rats that he can use to taste the bottles, in order to find out which is the poisoned one. Unfortunately, he has time only for one round of testing...
You may read the detailed story in the original kata.
Your task
Find the poisoned bottle!
You receive the number of bottles
and the number of rats
. You can test the wines with the provided function (see the initial code), specifying the bottle numbers for each rat. The result of the testing is the list of rats that died (if any). Return the number of the poisoned bottle.
Notes:
- rat numbers and bottle numbers start from 1
- the number of bottles can go as high as 30000 (and will be at least 2)
- you will always have enough rats to identify the poisoned bottle
And remember: you have only one round of test for each set of bottles. Make sure you save the King!
Examples
4 bottles and 3 rats:
# rats: #1 #2 #3 test_wines([1], [2], [3]) --> [2]
As rat #2 tasted bottle
2
and died, that is the poisoned bottle.6 bottles and 3 rats:
# rats: #1 #2 #3 test_wines([1, 2, 3], [3, 4, 5], [5, 6, 1]) --> [2, 3]
The only bottle that rat #2 and #3 both tasted was bottle
5
, so that is the solution.
My other katas
If you enjoyed this kata then please try my other katas! :-)
Translations are welcome!
Similar Kata:
Stats:
Created | Feb 13, 2020 |
Published | Feb 14, 2020 |
Warriors Trained | 144 |
Total Skips | 52 |
Total Code Submissions | 189 |
Total Times Completed | 19 |
Ruby Completions | 7 |
Python Completions | 14 |
Total Stars | 1 |
% of votes with a positive feedback rating | 79% of 7 |
Total "Very Satisfied" Votes | 5 |
Total "Somewhat Satisfied" Votes | 1 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 7 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |