Thursday, August 23, 2007
Riddles..
2).Imagine you have a closet full of shirts. It’s very hard to find a shirt. So what can you do to organize your shirts for easy retrieval?
3).What method would you use to look up a word in a dictionary?
4).You have eight balls all of the same size. 7 of them weigh the same, and one of them weighs slightly more. How can you fine the ball that is heavier by using a balance and only two weighings?
5).How do you cut a rectangular cake into two equal pieces when someone has already taken a rectangular piece from it? The removed piece an be any size or at any place in the cake. You are only allowed one straight cut.
Tuesday, August 14, 2007
Burning Fuses
You are given two fuses and a lighter. The fuses take one hour to burn. They burn at non-constant unknown rates; meaning it could take 40 minutes to burn half way and then 20 minutes for the other half, you do not know. You are told to make a timer using these fuses that will burn for 45 minutes. You can cut them, tie them in a bow, use them to floss with. . . anything you want.
Solution below..
This is because it takes half an hour for a fuse to burn completely through when lit from both ends and 15 minutes for the other half of the second fuse to burn through lit at both ends. You must convince yourself of this fact. Imagine a candle stick, if lit from both ends it would burn out in half the time.
Proof that it takes half the time of a fuse cut in half when the fuse is lit at both ends for non-constant fuses:
Consider our fuse being as long as a meter stick(arbitrary length, I could have picked any length as long as it takes one hour to burn when lit at one end)
Assume it takes an hour to burn when lit from one end.
Now lets say that after 30 minutes the fuse burned to the 30 cm (arbitrary mark) mark when lit from the 0 cm mark. What I have to now show is that it takes 30 minutes for the fuse to burn from the 100 cm mark to 30 cm.
If it did not take 30 minutes for the fuse to burn from the 100 cm mark to the 30 cm mark, the total burn time of the rope would not equal one hour.
For the second fuse, the key is that after the first fuse burns, whatever point the second fuse is at is the half burn time point for the second. Lighting the other end of the second fuse at this time will cause the 30 minutes of burn time the second fuse has left to become 15 minutes.
Monday, July 23, 2007
Bridge
person A: 1 minute
person B: 2 minutes
person C: 5 minutes
person D:10 minutes
Solution below...
1. A & B cross. total time: 2 minutes.
C |==========================| A
D | | B
|==========================| flashlight
2. B comes back. total time: 4 minutes.
C |==========================| A
D | |
B |==========================|
flashlight
3. C & D cross. total time: 14 minutes.
B |==========================| A
| | C
|==========================| D
flashlight
4. A comes back. total time: 15 minutes.
A |==========================| C
B | | D
|==========================|
flashlight
5. A & B cross. total time: 17 minutes.
|========= =============| A
| KABOOM! | B
|========= =============| C D
flashlight
another solution which is valid is to have A bring the flashlight back in step 2. it only changes the solution slightly. this is supposed to be a "classic" microsoft interview question but it seems absurdly easy to be a good interview question (especially coupled with the fact that everyone has probably heard it already).
Puzzle: Pirates
solution: most of the time i get people who give answers like "the most senior pirate takes half and divides the rest up among the least senior pirates." um, you missed the whole point to begin with. sorry.
any answer without a specific logic behind it is invalid. if i ask you why pirate 5 gave x coins to pirate 1, please don't say "because he's nice".
now for the real solution. pirate 5 being the most senior knows that he needs to get 2 other people to vote for his solution in order for him not to be executed. so who can he get to vote for him, and why would they choose to vote for him? if you start thinking that pirate 4 will never vote for him, because he would rather have 5 die and then be in charge and take it all for himself, you are on the right track. but it gets more complicated.
lets consider if there were only 1 pirate. obviously he would take it all for himself and no one would complain.
if there were 2 pirates, pirate 2 being the most senior, he would just vote for himself and that would be 50% of the vote, so he's obviously going to keep all the money for himself.
if there were 3 pirates, pirate 3 has to convince at least one other person to join in his plan. so who can he convince and how? here is the leap that needs to be made to solve this problem. pirate 3 realizes that if his plan is not adopted he will be executed and they will be left with 2 pirates. he already knows what happens when there are 2 pirates as we just figured out. pirate 2 takes all the money himself and gives nothing to pirate 1. so pirate 3 proposes that he will take 99 gold coins and give 1 coin to pirate 1. pirate 1 says, well, 1 is better than none, and since i know if i don't vote for pirate 3, i get nothing, i should vote for this plan.
now we know what happens when there are 3 pirates. so what happens with 4? well pirate 4 has to convince 1 other person to join in his plan. he knows if he walks the plank then pirate 3 will get 99 coins and pirate 1 will get 1 coin. pirate 4 could propose giving pirate 1 two coins, and surely pirate 1 would vote for him, since 2 is better than 1. but as greedy as he is, pirate 4 would rather not part with 2 whole coins. he realizes that if he gets executed, then pirate 3's scenario happens and pirate 2 gets the shaft in that scenario (he gets zero coins). so pirate 4 proposes that he will give 1 coin to pirate 2, and pirate 2 seeing that 1 is better than 0 will obviously vote for this plan.
a common objection is that pirate 2 is not guaranteed to vote for this plan since he might hope for the case when there are only 2 pirates and then he gets all the booty. but that is why i said that the pirates are extremely intelligent. pirate 2 realizes that pirate 3 is smart enough to make the optimal proposal, so he realizes that there will never be 2 pirates left, because 3 doesn't want to die and we just showed that 3 has a winning proposal.
so lets sum up at this point
Pirate 1 2 3 4 5
5. ? ? ? ? ?
4. 0 1 0 99 -
3. 1 0 99 - -
2. 0 100 - - -
1.100
once you see the pattern it becomes very clear. you have to realize that when a pirate's plan does not succeed then that means you are in the same situation with one less pirate.
1. pirate 1 needs 0 other people to vote for him. so he votes for himself and takes all the money. 2. pirate 2 needs 0 other people to vote for him. so he votes for himself and takes all the money. pirate 1 gets 0. 3. pirate 3 needs 1 other person to vote for him. he gives 1 coin to pirate 1 for his vote - if we are reduced to 2 pirates, pirate 1 gets 0 so pirate 1 knows 1 is better than none. pirate 3 takes 99. pirate 2 gets 0. 4. pirate 4 needs 1 other person to vote for him. he gives 1 coin to pirate 2 - if we reduce to 3 pirates, pirate 2 gets 0 so pirate 2 knows 1 is better than none. pirate 4 takes 99. pirate 3 gets 0. pirate 1 gets 0. 5. pirate 5 needs 2 other people to vote for him. its clear now that the 2 people he needs to convince are the 2 who get shafted in the 4 pirate scenario - pirate 3 and pirate 1. so he can give them each 1 coin (which is better than 0 - what they would get otherwise) and keep 98 for himself.
Pirate 1 2 3 4 5
5. 1 0 1 0 98
what happens if there are 15 pirates? pirate 15 needs 7 other people to vote for him, so he recruits pirates 13,11,9,7,5,3, and 1 with 1 coin each and keeps 93 coins himself. those pirates will all vote for him because they know that they get 0 coins if he dies and pirate 14 is in charge.
hope you enjoyed this one. its my favorite interview question of all. it really allows the candidate to ask a lot of interesting questions and its really amazing when they reach the solution all by themselves (as all fogcreek employees have done so far).
Friday, July 20, 2007
Gunshot : Puzzle
since 1/4
Monday, July 16, 2007
100 doors in a row
question: what state are the doors in after the last pass? which are open which are closed?
Solution below...
you can figure out that for any given door, say door #42, you will visit it for every divisor it has. so 42 has 1 & 42, 2 & 21, 3 & 14, 6 & 7. so on pass 1 i will open the door, pass 2 i will close it, pass 3 open, pass 6 close, pass 7 open, pass 14 close, pass 21 open, pass 42 close. for every pair of divisors the door will just end up back in its initial state. so you might think that every door will end up closed? well what about door #9. 9 has the divisors 1 & 9, 3 & 3. but 3 is repeated because 9 is a perfect square, so you will only visit door #9, on pass 1, 3, and 9... leaving it open at the end. only perfect square doors will be open at the end.
Wednesday, July 11, 2007
Puzzle : Red and Blue Marbles
Solution below..
for example, say we put all the red marbles into jar A and all the blue ones into jar B. then our chances for picking a red one are:
1/2 chance we pick jar A * 50/50 chance we pick a red marble
1/2 chance we pick jar B * 0/50 chance we pick a red marble
do the math and you get 1/2 chance for a red marble from jar A and a 0/2 chance for a red marble from jar B. add 'em up and you get the result = 1/2 chance for picking a red marble.
think about it for awhile and see if you can figure out the right combination. we had a 50/50 (guaranteed) chance in picking a red marble from jar A, but we didn't have to have 50 red marbles in there to guarantee those fantastic odds, did we? we could've just left 1 red marble in there and the odds are still 1/1. then we can take all those other marbles and throw them in jar B to help the odds out there.
let's look at those chances:
1/2 we pick jar A * 1/1 we pick a red marble
1/2 we pick jar B * 49/99 we pick a red marble
do the math and add them up to get 1/2 + 49/198 = 148/198, which is almost 3/4.
we can prove these are the best odds in a somewhat non-formal way as follows. our goal is to maximize the odds of picking a red marble. therefore we can subdivide this goal into maximizing the odds of picking a red marble in jar A and maximizing the odds of picking a red marble in jar B. if we do that, then we will have achieved our goal. it is true that by placing more red marbles into a jar we will increase the chances of picking a red marble. it is also true that by reducing the number of blue marbles in a jar we will increase the odds also. we've maximized the odds in jar A since 1/1 is the maximum odds by reducing the number of blue marbles to 0 (the minimum). we've also maximized the number of red marbles in jar B. if we added any more red marbles to jar B we would have to take them out of jar A which reduce the odds there to 0 (very bad). if we took any more blue ones out of jar B we would have to put them in jar A which reduce the odds there by 50% (very bad).
Tuesday, July 10, 2007
PUZZLE : THE WARDEN
"In the prison is a switch room, which contains two light switches labeled 1 and 2, each of which can be in either up or the down position. I am not telling you their present positions. The switches are not connected to anything.
"After today, from time to time whenever I feel so inclined, I will select one prisoner at random and escort him to the switch room. This prisoner will select one of the two switches and reverse its position. He must flip one switch when he visits the switch room, and may only flip one of the switches. Then he'll be led back to his cell.
"No one else will be allowed to alter the switches until I lead the next prisoner into the switch room. I'm going to choose prisoners at random. I may choose the same guy three times in a row, or I may jump around and come back. I will not touch the switches, if I wanted you dead you would already be dead.
"Given enough time, everyone will eventually visit the switch room the same number of times as everyone else. At any time, anyone may declare to me, 'We have all visited the switch room.'
"If it is true, then you will all be set free. If it is false, and somebody has not yet visited the switch room, you will all die horribly. You will be carefully monitored, and any attempt to break any of these rules will result in instant death to all of you"
What is the strategy they come up with so that they can be free?
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
HINT:
Take a long-term perspective. Solve the puzzler for three prisoners.
Solution below....
The leader is the only person who will announce that everyone has visited the switch room. All the prisoners (except for the leader) will flip the first switch up at their very first opportunity, and again on the second opportunity. If the first switch is already up, or they have already flipped the first switch up two times, they will then flip the second switch. Only the leader may flip the first switch down, if the first switch is already down, then the leader will flip the second switch. The leader remembers how many times he has flipped the first switch down. Once the leader has flipped the first switch down 44 times, he announces that all have visited the room.
It does not matter how many times a prisoner has visited the room, in which order the prisoners were sent or even if the first switch was initially up. Once the leader has flipped the switch down 44 times then the leader knows everyone has visited the room. If the switch was initially down, then all 22 prisoners will flip the switch up twice. If the switch was initially up, then there will be one prisoner who only flips the switch up once and the rest will flip it up twice.
The prisoners can not be certain that all have visited the room after the leader flips the switch down 23 times, as the first 12 prisoners plus the leader might be taken to the room 24 times before anyone else is allowed into the room. Because the initial state of the switch might be up, the prisoners must flip the first switch up twice. If they decide to flip it up only once, the leader will not konw if he should count to 22 or 23.
In the example of three prisoners, the leader must flip the first switch down three times to be sure all prisoners have visited the room, twice for the two other prisoners and once more in case the switch was initially up.
Monday, July 9, 2007
Puzzle : The Stark Raving Mad King
A stark raving mad king tells his 100 wisest men he is about to line them up and place either a red or blue hat on each head. Once lined up, they must not communicate amongst themselves nor attempt to look behind them nor remove their own hat.
The king tells the wise men that they will be able to see all the hats in front of them. They will not be able to see the color of their own hat or the hats behind them, although they will be able to hear the answers from all those behind them.
The king will then start with the wise man in the back and ask "what color is your hat?" The wise man will only be allowed to answer "red" or "blue," nothing more. If the answer is incorrect then the wise man will be silently killed. If the answer is correct then the wise man may live but must remain absolutely silent.
The king will then move on to the next wise man and repeat the question.
Before they are lined up, the king makes it clear that if anyone breaks the rules then all the wise men will die. The king listens in while the wise men consult each other to make sure they don't devise a plan to communicate anything more than their guess of red or blue.
What is the maximum number of men they can be guaranteed to save?
source : http://www.folj.com/puzzles/very-difficult-analytical-puzzles.htm
Solution:
You can save about 50% by having everyone guess.
You can save 50% or more if every even person agrees to call out the color of the hat in front of them. That way the person in front knows what color their hat is, and if the person behind also has the same colored hat then both will survive.
So how can 99 people be saved? The first wise man counts all the red hats he can see (all but his own) and then answers "blue" if the number is odd or "red" if the number is even. Each subsequent wise man should be able to then guess correctly the color of their hat, based on the number of red hats in front of them, and all the answers from all the wise men behind them.
For example if the first wise man answers "blue" he indicates to everyone that he sees an odd number of red hats. If the second wise man then sees an odd number of red hats, he can deduce that he has a blue hat on. He will then state "blue" so that everyone knows he still saw an odd number of hats. If the third wise man then sees an even number of red hats then he must be wearing a red hat. He will then state "red" so that everyone knows he saw an even number of hats. Etc..
This does not presume an even number of red and blue hats. There could be 94 blue hats and then 6 red ones. All the hats could be red.
Emporer and Wine
You are the ruler of a medieval empire and you are about to have a celebration tomorrow. The celebration is the most important party you have ever hosted. You've got 1000 bottles of wine you were planning to open for the celebration, but you find out that one of them is poisoned.
The poison exhibits no symptoms until death. Death occurs within ten to twenty hours after consuming even the minutest amount of poison.
You have thousands of prisoners at your disposal and just under 24 hours to determine which single bottle is poisoned.
What is the smallest number of prisoners you must have to drink from the bottles to be absolutely sure to find the poisoned bottle within 24 hours?
.....
The answer is 10.
Even if time is a constraint, the solution is 10. The explanation is given below. The trick is 10 bits are enough to represent 1024 numbers. so label the wine bottles as 1...1000. and number the prisoners also as 1...10 so that
bit 0 ---corresponds to prisoner 1
bit 1 --- corresponds to prisoner 2.
;
;
bit 9 --- corresponds to prisoner 10
Number the people 1 through 10. The first bottle of wine is assigned to no one. The first bottle will be drunk by the first person. The second person will drink the second bottle. The third bottle will be drunk by both the first and the second person. The fourth bottle will be drunk by the third person. The fifth bottle will be drunk by the third person and the first person. The sixth bottle will be drunk by the third person and the second person. The seventh bottle will be drunk by all three people, etc... That way if only the first and third people die, then you know it was the fifth bottle. With ten people there are 1024 unique combinations so you could test up to 1024 bottles of wine.
Each of the ten prisoners will taste from about 500 bottles and will have at least a fifty percent chance of living.
No, they wont die of alcohol poisoning. As long as each prisoner is administered about a millilitre from each bottle, they will only consume the equivalent of about one bottle of wine each.
It helps to understand binary numbers. Google it. Another way to picture this is to use a tree diagram, where each level of branching represents another person drinking a unique set of half of the bottles.