Sunday 25 October 2015

A good long techo discussion and i come up with this . Some insights into a problem long known and discussed . A good interview question that can be brought up for discussion and i totally loved it!!




King and Wine problem :-
The standard King and wine pblm is a very often asked puzzle . Suppose a king had 1000 bottles of wine and some traitor poisoned 1 of the bottles but was caught immediately after that .
The poison takes 1 hour to take to effect and even a single drop can cause death . The King wants to find which bottle had the poison. He can used prisoners to so the same .
What will the king do to find the poisoned bottle in 1 hour?

First solution -
This solution will get you least no of prisoners involved
Convert  each bottle to binary no .
bottle 1 = 0000000001 (10 digit binary)
bottle 2 = 0000000010
.....
bottle 1000 = 1111101000

Let each digit on this represent a prisoner . P1.......P10
So depending upon which prisoners die we can identify the bottle .

Suppose P3,P5, P6 ,P7 ,P8, P9 die , then it means that bottle
0111110100 = 500  had the poison.

This approach guarantees less prisoners are involved but can involved many deaths as well.

Second solution :-
This will guarantee that less of prisoners die

Align 1000 bottles into a 2 dimentional array (32 X 32 array)



 P1
…………
P32
P33
B1
 .............
B32
..
B33
 ...............
B64
P64
 ...................
B1000



P1 drinks from all bottles in the column P1 (B1, B33...)
P33 drinks from all bottles in column P33 (B1...B32)

Depending on which 2 prisoners die , We can find the bottle

(Extension to this -  instead of 2 direction use a 3 dimensional array (10 x 10 x10 ) and depend ingon which 3 prisoners die identify the bottle . Hence 30 prisoners)




No comments:

Post a Comment