thanks its almost same :) i was hoping for a diff answer (if exists) On Fri, Jul 22, 2011 at 4:25 PM, Rajeev Kumar <rajeevprasa...@gmail.com>wrote:
> Please check this : http://www.techinterview.org/post/526313890/bad-king > > On Tue, Jul 19, 2011 at 8:43 PM, sagar pareek <sagarpar...@gmail.com>wrote: > >> hey guys pls tell any other better solution ... >> >> >> On Tue, Jul 19, 2011 at 6:41 PM, sagar pareek <sagarpar...@gmail.com>wrote: >> >>> Question :- >>> >>> >>> >>> Once upon a time in ancient times there was a king who was very fond of >>> wines. He had a huge cellar, which had 1000 different varieties of wine >>> all in different caskets (1000 caskets in all). In the adjoining >>> kingdom there was a queen who was envious of the king’s huge wine >>> collection. After some time when she could not bear it any more she >>> conspired to kill her by poisoning all his wine caskets. So she one >>> sentry to poison all the caskets, but no sooner had the sentry poisoned only >>> one wine casket that he was caught and killed by the Royal guards. Now >>> the king had a major problem in his hand so as to identify the right casket, >>> which he gave to the Minister. Now the position had two peculiar >>> qualities >>> >>> >>> >>> Anyone who takes even one drop of poison will die. >>> >>> But, he will die only after one month. >>> >>> >>> >>> The king also gave the Minister 10 prisoners who could be used >>> as tasters, cause there lives was of no consequence to the king of kingdom >>> for that matter, and the Minister was given one month to find the poisoned >>> casket. Is it possible for the Minister to find out in one month? If >>> so how? If not then how many months are required? >>> >>> >>> >>> >>> >>> My solution :- >>> >>> This can be done in one month >>> >>> Think the solution in binary >>> >>> ok first i wanna ask u a question :- how many bits are needed to >>> represent the number 1000 ? >>> yeah u r right -> 10 bits >>> >>> so here is the solution >>> let if any prisoner alive it mean it doesnt die and it will be >>> represented by 1 else if he dies then he will be represented by 0 >>> number the prisoners from 0-9 with 0 the right most (LSB) >>> now what will be binary representation of 0 ? 0000000000 >>> so if 0th bottle is poisoned then all prisoners must die so taste the >>> 0th(actually 1st) wine to all the prisoners. >>> what is binary representation of 1? 0000000001 >>> so taste the 1st(actually 2nd) wine to all except the 0th prisoner. >>> for 2nd, all except 1st (considering 0th as lowest bit) one >>> >>> and so on............. >>> so at the end if suppose 6th and 2nd prisoner(consider 0 min and 9 max) >>> left alive then answer will be :- 1*2^5+1*2^1 +1 (note:- here ^= power) >>> >>> >>> if anyone have more general solution pls let me know >>> >>> *I hope this is useful :) :)* >>> >>> >>> >>> -- >>> **Regards >>> SAGAR PAREEK >>> COMPUTER SCIENCE AND ENGINEERING >>> NIT ALLAHABAD >>> >>> >> >> >> -- >> **Regards >> SAGAR PAREEK >> COMPUTER SCIENCE AND ENGINEERING >> NIT ALLAHABAD >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > Thank You > Rajeev Kumar > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.