Beta

The Poisoned Bottle

7 of 19anter69

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!

Puzzles

Similar Kata:

Stats:

CreatedFeb 13, 2020
PublishedFeb 14, 2020
Warriors Trained144
Total Skips52
Total Code Submissions189
Total Times Completed19
Ruby Completions7
Python Completions14
Total Stars1
% of votes with a positive feedback rating79% of 7
Total "Very Satisfied" Votes5
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes1
Total Rank Assessments7
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • anter69 Avatar
  • Kacarott Avatar
Ad