Saturday, May 30, 2009

The prisoners of the Zhou Dynasty


Two prisoners were sentenced to death by King Xuan of Zhou and were kept in two different inaccessible cells. They were to be put to the gallows the day after. However, King Xuan wanted to give them a last chance. Since he was very fond of riddles, he came up with one for the prisoners which if they solved, they would be set free. The prisoners were told that they would be put into a single cell for a day when they can discuss their strategy, after which they would again be sent back to their respective cells. One of the prisoners would then be given 5 playing cards out of the pack of 52 cards. He can send four of these five cards to the other prisoner through the jailor one by one after which the second prisoner has to guess the one card (number and suit) which is left with the first prisoner. If he guesses right, both the prisoners would be set free but if not they would be hanged the same day.
What strategy could they possibly come up with which could save them?

Link to the Solution

Friday, May 29, 2009

Solution to the pistol duel


Link to the Problem

Since you as a cyborg are intelligent, assuming the other two cyborgs also to be equally intelligent, Sujit gave the right solution! Here goes my solution assuming the same!

Lets analyze the scenario when both you and the 50% accuracy cyborg miss:
The 100% accuracy cyborg gets the chance now and he surely hits. So he would want the cyborg who would have a lower accuracy of hitting to get the next chance so that he has a higher probability of surviving and hence he would choose to kill the 50% accuracy cyborg.
The 50% accuracy cyborg knows this and hence would never want the 100% accuracy cyborg to get a chance. So in his turn he would want to kill the 100% accuracy cyborg and hence would aim at him.
Now consider your first turn. If you choose to aim at the 50% accuracy cyborg and if you hit then the 100% accuracy cyborg would aim at you and you are sure to be dead and if you miss, the 50% accuracy cyborg would get the next turn and he would aim at the 100% accuracy cyborg for reasons mentioned above. On the other hand if you aim at the 100% accuracy cyborg and if you hit, then the 50% accuracy cyborg would aim at you but this time you have 50% chance of survival. However, if you miss, the 50% accuracy cyborg would again aim at the 100% accuracy cyborg(same as above). Therefore, you have more chances of survival if you aim at the 100% accuracy cyborg than if you aim at the 50% one.
Hence, you aim at the cyborg with 100% accuracy!

Wednesday, May 20, 2009

The pistol duel


You are a cyborg in a pistol duel with two other cyborgs. You have been programmed to fire pistols with an accuracy of 33%. The other two cyborgs shoot with accuracies of 100% and 50% respectively.
The rules of the duel are one shot per-cyborg per-round. The shooting order is from worst shooter to best shooter. Thus, you go first, the 50% guy goes second, and the 100% guy goes third; repeat. If a cyborg dies, we just skip his or her turn. Which cyborg should you shoot at in round one to maximize your chances of survival over time?

Link to the Solution

Solution to Getting all possible denominations


Link to the Problem

Consider the bags as switches, switching the first bag on indicates that u give away the first bag full of coins. This can be represented as a 10 bit long binary number with which you can represent 0 to 1023 numbers. But here you have only 1000 coins. With 9 bits you can represent numbers from 0 to 511. Put 2^0 = 1 coin into the first bag, 2^1 = 2 coins into the second bag, 2^2 = 4 coins into the third bag, ... so on till you put 2^8 = 256 coins into the 9th bag. With this arrangement you can give away all denominations till (2^10-1) = 511. And you have 489 coins left. Put all of that into the 10th bag and now to represent any number from 512 to 1000 (lets say N) just give away the bag with 489 coins and the combination of bags which equate to (N-489) which will always be less than or equal to 511 (since N <= 1000) and is hence achievable using the combination of other 9 bags!
Hence, the number of coins that you put into the bags are 2^0, 2^1, 2^2, .... , 2^8, 489.

Tuesday, May 12, 2009

Getting all possible denominations


Divide 1000 one rupee coins into 10 bags such that you are able to arrive at any denomination less than or equal to Rs.1000 with some combination of these bags.

(If you had put 600 one rupee coins in one bag and 400 one rupee coins in another bag, you can arrive at Rs.400, Rs.600 and Rs.1000 using these two bags. You have to divide the coins into ten such bags so that u can arrive at each and every denomination <= Rs.1000 using the bags)

Link to the Solution

Wednesday, May 6, 2009

Solution to the five greedy pirates


Link to the Problem

The idea is to reduce the number of participants (greedy pirates) and see what happens in that case and start reasoning based on that. One more thing to note here is that a pirate would accept a proposal only if he knows that in case he would not accept the proposal, he would get less of the treasure. Let's say we identify the pirates by the number of years of experience they have.
Now consider the case when pirates 5, 4 and 3 killed and only 2 and 1are left. Now 2 has to get a vote from 1 to stay alive. However, 2 can never give 1 more number of coins that what he would get by killing 2 and hence 2 can never satisfy 1. Therefore, 2 would never want to be left alone with 1 and 3 being intelligent knows that!
Now consider the case when pirates 5 and 4 are killed and only 3, 2 and 1 are left. 3 has to get one more vote from either 2 or 1 to stay alive. And 3 knows that 2 never wants to stay alone with 1 and hence would always vote for 3. So 3 being so lucky could keep all the 1000 gold coins and give nothing to 2 and 1 and still stay alive. So 2 and 1 would not want 3 to be a proposer of the split even if they get one gold coin each and 4 being intelligent knows that!
Now consider the case when only the pirate 5 is killed and 4, 3, 2 and 1 are left. 4 has to get 2 more votes to get a majority which it can get from 1 and 2 by giving them 1 gold coin each and keeping the rest 998 with himself and giving 3 nothing. So 3 would not want 4 to propose even if he gets 1 gold coin for himself, and 1 and 2 would not want 4 to propose if they get more than 1 gold coin which 5 being intelligent knows!
Now consider the real problem wherein 5 has to propose so that he gets the maximum and doesn't get killed. He needs 2 more votes minimum inorder to stay alive. He could get one vote from 3 by giving him one gold coin. And for one more vote he could give either 1 or 2 two gold coins as discussed above! So he keeps 997 gold coins for himself, gives 1 gold coin to 3 and give 2 gold coins to either 1 or 2!

Hence the proposal is :
5 - 997 gold coins
4 - 0 gold coins
3 - 1 gold coin
2 - 0 gold coins or 2 gold coins
1 - 2 gold coins or 0 gold coins

Monday, May 4, 2009

The five greedy pirates!


There are 5 pirates, all of them being equally greedy. They have varied number of years of experience. Say for convenience sake 5, 4, 3, 2 and 1. They find a booty of 1000 gold coins which they want to split amongst themselves. Everyone being greedy, wants the most for themselves. So they device a scheme!
They agree that each one would propose a split starting with the most senior person to the least senior person. If there is no majority, the guy who proposed will be killed and then the next guy gets the chance. So it'll be 5 first then 4 etc. How does the guy with 5 years experience propose to split the coins so that he gets the max and does not get killed?

Link to the Solution