Tuesday, June 4, 2013

Most asked IT interview puzzels


Strange Trip
You travel 100 miles north, 100 miles east, and then 100 miles south. You are at the same point that you started from. Describe all the places on earth this could be, if any
Answer: At the south pole.
Or, 100 miles south of any point on the circle around the north pole that is 100 miles in circumference.
Or, 100 miles south of any such circle whose circumference is an integral fraction of 100 miles.

Three Cards
There are 3 cards: one is all red, one is all blue, and the third is blue on one side and red on the other. The cards are shuffled. You pick one at random and it is blue on the side facing you. What are the chances that it is also blue on the other side?
Answer: 2/3. Two of the three blue sides have blue on the other side. You might think the chances are 1/2 because you could have one of two cards, but you actually get a side at random, not a card, so you are more likely to have the blue/blue card than the red/blue card.
Here is another way to think of it: When you pick a card at random, the chances of it being the same on both sides (either all red or all blue) are 2 out of 3, and this doesn't change just because you see one of the sides. If they did, they'd change no matter which color you saw, and it wouldn't even matter if you looked. So when you do see the blue side, the red/red card is eliminated, but the blue/blue card still has a 2/3 probability.
Monty Hall Problem
A
Behind 1 of 3 closed doors is a prize. You pick one of the doors. Monty, knowing where the prize is, opens one of the other doors which is empty. You are given the choice of sticking with your choice or switching to the other unopened door. Should you switch? What are your chances of winning if you do?
Answer: You should switch. Your chances are 2/3 if you do. Switching always works if your initial pick was wrong (2/3 of the time) and only fails if your initial pick was right (1/3 of the time). The initial chances of your first choice were 1/3, and opening another door without the prize doesn't actually change that, so the remaining door now has a 2/3 chance because the chances of all possibilities must sum to 1.
Many people think the chances are 1/2 because there are two doors left, but that is not correct. If you're not convinced 2/3 is correct, consider a 100 door version: you pick 1 door and Monty opens 98 other doors avoiding the one with the prize. Now you have a 99% chance if you switch.
4 Door Monty Hall Problem
A
Behind 1 of 4 closed doors is a prize. You pick door 1. Monty, knowing where the prize is, opens the 4th door which is empty. You switch your choice to door 2. Now Monty opens another door which is empty: door 3. Given the choice, should you switch back to door 1, and what are your chances of winning if you do?
Answer: Yes, your chances are 5/8 if you switch. The initial chances of your first choice were 1/4, and opening another door without the prize doesn't change that, so the remaining 2 doors now have a 3/8 chance because the chances of all possibilities must sum to 1. But then when Monty opens door 3, using the same reasoning, door 2 stays at 3/8 chance and so the remaining door changes to 5/8.
Monty Fall Problem
A
Behind 1 of 3 closed doors is a prize. You pick one of the doors. Monty accidentally slips and falls, knocking one of the other doors open at random which happens to be empty. You are given the choice of sticking with your choice or switching to the other unopened door. What are your chances of winning if you switch?
Answer: Your chances are 1/2 whether you switch or not. This result differs from the standard Monty Hall Problem because here Monty might have opened the door with the prize. We ignore those cases because we are told he didn't, but it still affects the odds. If your initial pick is correct, a random other door will always be empty, but otherwise it is only empty half the time. If you picked door 1, there are 4 equally likely cases where the randomly opened other door is empty: the prize is in door 1 and door 2 is opened, the prize is in door 1 and door 3 is opened, the prize is in door 2 and door 3 is opened, or the prize is in door 3 and door 2 is opened. Since 2 of the 4 empty other doors occur when you picked correctly, your chances are 1/2 if you switch or not.
Two Envelopes
A
(Also known as the exchange paradox.) There are two envelopes, one contains twice as much money as the other. You pick one at random and find $100 inside. What is the "expected value" of the amount in the other envelope? Given the option, should you switch? Does it matter how much you found in that first envelope? Does it matter if you open the envelope?
Answer:
This is a strange paradox because it appears that the expected value is the average of double and half which is 1.25 X so you should switch. However, this would be true for any value of X you find, so it wouldn't even matter if you open the envelope. This same logic suggests that you should also immediately switch back to the original envelope again, which doesn't make sense at all.
The fault in this reasoning is that you are not actually given enough information to know that double and half are equally probable. You would need to know more about the process by which the amounts in the envelopes were determined or what the probability distribution of possible amounts is. For example, if there was a known limit for the amounts, you would switch if and only if 2X was within that limit. Note that it is impossible to have an even distribution of all possible values without also having an upper bound. If the amounts can go to infinity, there would have to be some uneven probability distribution, and you would need to know what that was to solve the problem properly.
Given the lack of any information like this, I believe the correct answer is: It does not matter if you switch.
Three Envelopes
A
There are three envelopes with different amounts of money in them. You pick one at random and open it. You then have the option to switch and open a second envelope. Again, you may switch to the third envelope if you'd like. However, if you switch you must discard the opened envelope and you can never switch back to it. Is there a strategy that gives you better than 1/3 chances of getting the best envelope, and if so what are those chances?
Answer:
Yes, you can get the best envelope 1/2 of the time. Always open a 2nd envelope. If it is larger, keep it. If it is smaller, open the 3rd envelope.
After opening 2 envelopes, the largest of those has a 2/3 chance of being the best, and the unopened 3rd envelope has a 1/3 chance of being best. With this strategy, half the time (when the 2nd is larger) you're improving your odds from 1/3 to 2/3. The other half (when the 2nd is smaller and you switch to the 3rd) they're still 1/3. So on the average your chances are 1/2.
What's Next?
A

What is the next figure in this sequence?
Answer:
         
Look at just the right-hand side of each figure.
Helium
A
A helium balloon is in your car. How does it move when you slam on the brakes?
Answer: It moves backwards. The deceleration pushes the air in the car forwards which causes the balloon to move in the other direction.
Urns with Balls
A
There are 2 urns filled with 100 ping pong balls total. 50 ping pong balls are white and 50 are black. I reach randomly into one of the urns, stir, and pick one ball without looking. What are the highest possible chances of me picking a white one that you can cause if you arrange the balls in the urns ahead of time?
Answer: 74/99. Put 1 white ball in one urn and the rest in the other.
Bean Bag
A
A bag contains a single bean, known to be either white or black. A new white bean is added to the bag, and it is shaken. A bean is taken back out, and it is white. What are the chances the remaining bean is also white?
Answer: 2/3. You might think it should remain at 1/2 since you didn't change the initial state of the bag, but this is incorrect. There are 3 equally probable ways you could pick a white bean: 1st bean was black and 2nd was picked, 1st bean was white and 2nd was picked, or 1st bean was white and also picked. 2 of those 3 have a white bean left in the bag.
Apples and Oranges
A
Three boxes each contain 20 pieces of fruit and are labeled "apples", "oranges", and "apples and oranges". The labels were correct but have been mixed up and are now all on the wrong boxes. What is the minimum number of fruits you need to inspect to learn the correct contents of all three boxes?
Answer: You only need to inspect one piece of fruit. Take it from the "apples and oranges" box. If it's an apple, that box must be all apples, since all boxes were labeled wrong. Then the box labeled "oranges" must actually be apples and oranges because we now know it's not apples, and finally the box labeled "apples" must be oranges.

Four Trees
A
A farmer claims to have 4 trees on his land all equidistant from each other. Could this be true?
Answer: Yes. If one or more trees are on a high hill they could form a tetrahedron and all be equidistant.
Suicidal Spots
A
In a far away land, there is an unusual tribe of 300 perfectly logical and perfectly intelligent people. Each member has a visible spot on the back of his or her head, some are red and some are black. Nobody knows the color of their own spot, but they do know the color of everyone else's. If a tribesman ever realizes the color of his own spot it is strict custom that he publicly commit suicide the following morning, so they never mention spot colors, and have no mirrors. But then one day an American tourist visits this land and announces to the entire tribe: "I can see that at least one of you has a red spot." The tourist leaves and returns a year later. What has happened?
Answer: They are all dead. Solve recursively: If only one had red he knows it must be him. After he goes, the others know he must have seen only black spots, so then they all go. If two have red, they see only one other red, and when the one other doesn't go the first morning, they both go the second morning, etc.
One Question
A
You are shipwrecked on an island. There is a fork in the path to the other side, one way leads to a safe village, the other leads to hungry cannibals. There are twin brothers who both know which path is which, but one of the brothers is honest, and the other always lies. You may ask one of them a single question. What should it be?
Related puzzle: what one question would you ask if there is just one person who is honest or lies but you don't know which?
Answer: "Which path would your brother tell me leads to the cannibals?" then go that way. Or to ask just one person: "If I were to ask you which path leads to the cannibals, what would you say?" and go the other way.
Three Random Hats
A
Three people are given hats. Each hat is either red or blue, chosen at random. Each person can see the other 2 hats, but not their own. They each must simultaneously either guess their own hat's color, or pass. No communication is allowed, although they can agree on a strategy ahead of time. What strategy will give them the best chances of at least one person guessing right, and nobody guessing wrong?
Answer: If the 2 hats you see are the same, guess the opposite color, otherwise pass. If all 3 players use this rule, it works 75% of the time. It fails only when all the hats are the same color.
This is a little counter-intuitive because your chances of having a blue hat are still 50% even if you see 2 red hats, so each player will guess wrong half of the time. However, all 3 players will be wrong at the same time in 2 of the 8 cases (all red or all blue). For the other 6 of 8 cases, one will guess right, and the others pass, so it still works.
Two Random Hats
A
Two people are given hats. Each hat is either black or white, chosen at random. Each person can see the other hat, but not their own. They each must simultaneously guess their own hat's color. No communication is allowed, although they can agree on a strategy ahead of time. What strategy will give them the best chances of at least one person guessing right? (In this version there is no penalty for a wrong guess if the other guesses right.)
Answer: One person always guesses the color of the other's hat. The other person always guesses the opposite color of the other's hat. This always works! If the hat colors are the same, they guess different colors and one of them is always right. If the hat colors are different, they guess the same color and one of them is always right.
Northwest Spiral
A
Two pilots fly from the Equator to the North Pole. The first flies north in a straight path. The second flies on a spiral path by always heading northwest. How far does the second pilot travel? (relative to the first)
Answer: sqrt(2). The second pilot is always heading 45 degrees off from north, so he always needs to travel sqrt(2) farther to make the same northerly progress.
Odd Ball
A
There are 12 equal sized balls. One ball has a slightly different weight (more or less) than the other 11. Can you use a balance scale only 3 times to find the odd ball?
Answer: First weigh 4 balls vs 4.
If they balance:
You know the odd ball is one of the other 4 and you can divide-by-2 search from there by just weighing 2 of them and then 1 against the normal balls.
If the initial 4 vs 4 don't balance:
Name those 8 balls H or L for heavier and lighter as appropriate, and call the other normal balls N.
Balance (2H + 2L) vs (1L + 1H + 2N).
If that balances:
You know the odd ball is one of the other two H or L, which you can determine with a final weighing as above.
If that doesn't balance:
You have narrowed it down to 3 possible balls, because the tipping direction must be consistent with the previous weighing.
If the (2H + 2L) side is heavier:
It must be one of those 2H or else the 1L from the other side.
Weigh those 2 H balls against each other:
If it balances: the 1L from the other side is the odd ball.
If it tips: the heavier one is the odd ball.
If the (2H + 2L) is lighter, do the symmetrical thing as above reversing L and H.
There are variations on this scheme that also work.

Weighing 9 Balls

You have 9 balls, equally big, equally heavy - except for one, which is a little heavier.
How would you identify the heavier ball if you could use a pair of balance scales only twice?
Answer: Divide the 9 balls into 3 groups of 3. Compare the weight of two of those groups.
The heavier group should then be obvious, it will either tip the scales, or, if the scales stay balanced, then it is the group you didn't include. Now, choose 2 balls from this group and compare their weights, and using the same logic as before, the heavier ball will be obvious.
Bags of Gold
A
Ten bags each contain nine pieces of gold. The gold pieces are all supposed to weigh 1 ounce, but the pieces in one bag weigh only .9 ounces. Use an accurate scale just once to find which bag contains the lighter pieces.
Answer: Take 1 piece from the 1st bag, 2 pieces from the 2nd bag, and so on up to 9 pieces from the 9th bag. The total weight W would normally be 45. If it is, the 10th bag has the lighter pieces. Otherwise the number of the guilty bag is (45 - W) x 10.
Fair Cake
A
When two people want to share a cake fairly, one cuts, and the other chooses. Assuming this is a fair scheme, devise a similar scheme for 3 people and 1 cake. Nobody should get short caked even if the other 2 cooperate.
Answer: A cuts off a piece. B has the option to reduce that piece and take it, and then C has the same option. The remainder of the cake is split between the other 2 people with the usual "one cuts and the other chooses".
Alternate recursive method: Starting with approximate thirds, each person can swap with either of the other 2 but then must give at least a crumb back to whoever he swaps with. This cycles until nobody wants to swap anymore.
Light Switches
A
There are 3 incandescent light bulbs in one room and 3 switches for these bulbs in another room. No light from the bulbs can be seen outside of their room. You are allowed to enter the room with the bulbs only once. How can you figure out which switches are connected to which bulbs?
Answer: Start with all switches off. Turn switch A on and wait 10 minutes or so. Turn A off and B on. Go into the room. Light A is off and warm, B is on, and C is off and cold.
Grid of Tiles
A
There is an empty 8x8 grid, except two opposite corners are missing. Can you tile the rest with 1x2 tiles?
Answer: No. If the grid is checkered, each tile must cover 1 black and 1 red square. However both missing corners are the same color, so there must be 2 squares with the other color that can never be covered.
1x3 Tiles
A
Can you cover an 8x8 grid with 1x3 tiles and a single 1x1 tile? If so, in what locations can the 1x1 tile be?
1x3 Tiles
Answer: Yes. The 1x1 tile can only be in a 3,3 position. If you label the squares of the grid as follows:
X . , X . , X .
, X . , X . , X
. , X . , X . ,
X . , X . , X .
, X . , X . , X
. , X . , X . .
X . , X . , X .
, X . , X . , X
Each 1x3 tile must cover exactly one of each type. There is one more X than dots or commas so the 1x1 square must cover some X position. If you turn this pattern the other way, the same should still be true, and there are only four X positions that remain X after you turn it:
, X . , X . , X
X . , X . , X .
. , X . , X . .
, X . , X . , X
X . , X . , X .
. , X . , X . .
, X . , X . , X
X . , X . , X .
Here is an example solution:
- - - | | - - -
- - - | | - - -
| | X | | - - -
| | - - - - - -
| | - - - - - -
| | | | | - - -
| | | | | - - -
| | | | | - - -

Cheese Cubes
A
A block of cheese is cut into a 3x3x3 grid of sub-cubes. A mouse starts eating one corner, and moves on to adjacent pieces until they are all eaten. Could he eat the middle piece last?
Answer: No. If the grid is checkered so adjacent cubes are different colors, the mouse must always alternate colors. There are an odd number of cubes so the mouse must end on the same color as he starts, but the center is not the same color as the corners.

Measuring with Jugs
A
Using a 5 liter jug, a 3 liter jug, and a hose, can you measure 4 liters of water?
How about measuring 1 liter?
Answer: To measure 4 liters: fill the large jug and pour off 3L by filling the small jug, to leave 2L. Empty the small jug, and transfer the 2L over to it. Then fill the large jug again and pour off 1L by topping off the smaller jug. That leaves 4L in the large jug.
To measure 1 liter: fill the small jug and pour that 3L into the large jug. Fill the small jug again and pour off 2L by topping off the large jug. That leaves 1L in the small jug.
Burning Fuses
A
You have 2 lengths of fuse and 2 matches. One fuse will burn from start to end in 10 minutes, and the other in 15 minutes. However, their burn rate is not steady along their lengths. Measure 20 minutes of time
Answer: Light both ends of the 10 minute fuse at once. When those burning ends meet somewhere in the middle, light the 15 minute fuse. When that is finished burning, 20 minutes are up.

Rope Escape
A
You have 150 meters of rope and a knife and need to escape from the roof of a 200 meter burning building. There are places to tie the rope to the building only at the roof, and at a ledge halfway down. How can you make it down without jumping?
Answer: Cut the rope into two pieces of 100 and 50 meters. Tie one end of the smaller piece to the roof and tie a small loop in the other end around the middle of the larger piece, so the larger piece is doubled up and together they hang down 100 meters to the ledge. Climb down to the ledge and then unthread the 100 meter piece which can be used to climb down the rest of the way.

Pocket Change
A
If all the coins in my pocket except two are pennies, all except two are nickels, and all except two are dimes, how much money do I have?
Pocket Change
Answer: 16 cents: 1 penny, 1 nickel, and 1 dime.
Gloves and Germs
A
You have 3 cultures of highly contagious and deadly germs. As part of an important experiment you must squeeze each culture once with your entire hand. However, you have only 1 pair of latex gloves. You must not contaminate any culture with another or with germs from your skin. The gloves can be worn on either the left or right hand. How can you complete your experiment without contaminating anything?
Answer: Put both gloves on the same hand and squeeze the 1st culture. Take the outer glove off and turn it inside out (it is now dirty inside and clean outside). Use the glove that is still on to squeeze the 2nd culture. Put the second glove back on over the first (so their dirty sides touch) and squeeze the 3rd culture.
Each squeeze makes 2 sides of a glove dirty (inside and out). 3 squeezes makes 6 sides dirty, but you only have 4 total sides. Therefore you know you must somehow re-use the same side that touches your skin for all 3 squeezes, as above.
Mixed Up Liquids
A
There are two equally filled jars, one contains milk, the other water. A teaspoon of milk goes into the water and is stirred. Then a teaspoon of the mixture goes back into the milk. Is there more water in the milk or milk in the water?
Answer: They are equal. Call the initial amount of liquids in the jars J, measured in teaspoons. When you add a teaspoon of milk to the water, the milk ratio of the first jar becomes M1 = 1/(J+1) and the water ratio is W1 = J/(J+1). Then, when you add a teaspoon of the mixture back to the water, the resulting water ratio is W1/J = 1/(J+1) = M1.

Feynman's Sucking Sprinkler
A
         
If you take a water sprinkler like the one above and put it under water, it will spin clockwise as it would on land. But what happens if you then reverse the flow so it sucks in water? Would it spin, and if so, in which direction?
Answer: The net change in momentum is zero, so it should not spin. The sucking might tend to make it go backwards, but then the change in momentum at the corners would cancel that.

Train Full of Water
A
A train car is at rest on a frictionless track. The car is full of water and has a spout pointing downwards on the far right end. The spout is opened and the water pours out. Describe the movement of the car, if any.
Answer: (Subject to debate.) The train moves to the left as the water moves to the right to get to the spout. But then the water leaving moves to the left and pushes the train back towards the right to conserve momentum, so the train ends up with a slight rightward velocity.
Joe and Billy are having a one-dimensional battle by shooting at each other through a long frictionless tube. Their guns each fire 10 balls in rapid succession, and all the balls enter the tube before any collide. The balls are perfectly elastic, have equal mass, are are shot at the same speed. Where to the balls end up and how many total bounces occur?
Answer: All the balls return to their shooter, and there are 100 total bounces.
When two bodies of equal mass have an elastic collision in one dimension, they just swap velocities, as if they pass through each other. If they did pass through each other, each would pass the 10 balls shot from the other direction, which gives 10x10 total bounces.
Another way: assuming the balls are regularly spaced, bounces occur at regular time intervals. First 1 bounce, then 2 at once, then 3, etc up to 10 bounces, and then from 9 back down to 1 again. This sums to 100 total bounces.
Yet another way: the 1st balls bounce 19 times (deflecting the energy from all the other balls), the 2nd balls bounce 17 times, the 3rd balls 15 times, etc up to the last balls which bounce only once. This also sums to 100 total bounces. (There are two of each 1st ball and 2nd ball etc, but each bounce involves 2 balls).
Bubbles in Space
A
Two balls of matter in empty space would move towards each other. What if all space were filled with a frictionless deformable substance, except for two empty bubbles? How would the bubbles move?
Bubbles in Space
Answer: Towards each other.
Flipped Cards
A
You are blindfolded and given a deck of 52 cards with 10 of the cards flipped upside down at random. Can you divide the deck into two parts that contain the same number of flipped cards? The two parts may have different numbers of cards and you may flip cards over, but you may not look at any cards.
Flipped Cards
Answer: Take any 10 cards from the deck and flip them all over. Those will now contain the same number of flipped cards as the rest of the deck. If x cards of those 10 were already flipped, those will get unflipped, so both parts now have 10-x cards flipped.
Fox in a Hole
A
There are 5 holes in a row. A fox spends each day in a hole, but always moves to an adjacent hole the next day, either right or left. You want to find the fox but you only get to inspect one hole per day. What is a strategy for finding the fox in the fewest days?
Six Chop Sticks
A
Using 6 equal length chop sticks make exactly 4 equilateral triangles.
Answer: Make a 3d tetrahedron. Each of its 4 sides is a equilateral triangle.
Stick Boxes
A
         
Make 4 equal sized squares out of these 5 by moving only 2 sticks, and leave no extra sticks.

Answer:
         

If 4 boxes are made from 16 sticks, you know that no boxes can share edges, only corners.
Fish Sticks
A
                   
Point the fish the other way by moving only 3 sticks.

Answer:
         

Ten Points
A
Can you arrange 10 points so that 5 lines can each be drawn through 4 points?
Answer:
         
Arrange the points in a star shape, with 5 at the star's points, and 5 at the inner intersections.


Connect the Dots
A
                   
Connect these 9 dots with only 4 connected straight line segments. (Don't lift your pencil.)

Answer:
         
A literal example of "thinking outside the box".

Four Points and Two Distances
Arrange 4 points in a plane so there are only 2 distinct distances between the 6 pairs of points. How many configurations like this are there?

Answer: There are 6.
Six Marbles
A
If you have 2 red, 2 green, and 2 blue marbles, can you arrange them so each one touches all four marbles of a different color?
Answer: Arrange them in the shape of a 3D octahedron, with each pair of colors at opposite vertices.
Wire Cube
A
What is the minimum number of wires needed to make a cube? (Bend but don't double the wires.)
Answer: 4. Each cube vertex is formed by 3 edges so you need a minimum of one wire-end for each. There are 8 vertices and 4 wires have 8 ends.
Cube Vision
A
What is the maximum number of sides of a cube that you can see at once? The cube may be any size. The sides are thin but opaque so you can't see through them, and you can't use mirrors or other reflections
Answer: You can see all 6 sides if you are inside a large cube and looking outwards from near one of the corners. (For this puzzle you need to think inside the box!)
If you couldn't get inside, then you could instead see 5 sides of a small cube if you hold it near your nose at a certain angle and look slightly cross-eyed at it.
Bookworm
A
A encyclopedia with ten 200 page volumes is sitting on a bookshelf in the usual order. A bookworm starts on the first page and eats in a straight line to the last page. How many total pages does he eat through?
Answer: 1602 (or 1600 if you don't count the first and last pages). Books are normally arranged on a bookshelf in order starting with volume 1 on the left, and with their binding facing outwards. Viewing books this way, the first page of a book is on its right and the last page is on its left, so the worm actually only eats through the middle 8 volumes.
Five Pirates
A
Five pirates of different ages have 100 gold coins, and they decide to split the coins using the following rules: the oldest pirate proposes how to divide the coins, and all pirates vote for or against that plan. If 50% or more of the pirates approve, then the coins will be shared that way. Otherwise, the pirate proposing the plan is thrown overboard, and the process is repeated with the remaining pirates. Assume all the pirates are predictably very intelligent and very greedy. What will happen?
Answer: The oldest pirate will propose 1 coin for the youngest, 1 for the middle pirate, and 98 for himself, and 3 of the 5 pirates will approve that plan.
Name the pirates A,B,C,D,E from youngest to oldest, and work back from 2 pirates, assuming the others had been thrown overboard because their plan did not pass:
If 2 pirates: B proposes "0, 100"  for A and B giving all coins to himself because his 50% vote is enough to pass any plan.
If 3 pirates: C proposes "
1, 0, 99"  (for A,B,C) and A would approve because otherwise he'd get nothing on the next round with 2 pirates above.
If 4 pirates: D proposes "
0, 1, 0, 99"  (for A,B,C,D) and B would approve because otherwise he'd get nothing on the next round.
If 5 pirates: E proposes "
1, 0, 1, 0, 98"  and A and C approve because otherwise they'd get nothing on the next round.
The pirates are intelligent enough to anticipate all of this, and so only the last case actually occurs, with nobody being thrown overboard.
Of course if they were very intelligent they wouldn't have agreed to these rules in the first place...
100 Pirates
A
Similar to above but with the quantities flipped: 100 pirates of different ages have 5 gold coins, and they decide to split the coins using the following rules: the oldest pirate proposes how to divide the coins, and all pirates vote for or against that plan. If 50% or more of the pirates approve, then the coins will be shared that way. Otherwise, the pirate proposing the plan is thrown overboard, and the process is repeated with the remaining pirates. Assume all the pirates are predictably very intelligent and very greedy. Also if a pirate figures his vote will not make a difference, he'll act in a bloodthirsty way and vote against the plan. What will happen?
Answer: The oldest 26 pirates will be thrown overboard. The 74th oldest will then propose giving one coin to 5 of the youngest 42 pirates, and this will be approved by 50% of the vote.
Number the pirates from youngest to oldest, and work back from 2 pirates, assuming the others had been thrown overboard because their plan did not pass. This starts out similar to the 5 pirate version of this puzzle, but then gets more interesting:
If  2 pirates:  #2 proposes "0, 5"  giving all coins to himself because his 50% vote is enough to pass any plan.
If  3 pirates:  #3 proposes "
1, 0, 4"
If  4 pirates:  #4 proposes "
0, 1, 0, 4"
If  5 pirates:  #5 proposes "
1, 0, 1, 0, 3"
If  6 pirates:  #6 proposes "
0, 1, 0, 1, 0, 3"
If  7 pirates:  #7 proposes "
1, 0, 1, 0, 1, 0, 2"
If  8 pirates:  #8 proposes "
0, 1, 0, 1, 0, 1, 0, 2"
If  9 pirates:  #9 proposes "
1, 0, 1, 0, 1, 0, 1, 0, 1"
If 10 pirates: #10 proposes "
0, 1, 0, 1, 0, 1, 0, 1, 0, 1"
If 11 pirates: #11 proposes "
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0"  These can't keep any for themselves, but they live.
If 12 pirates: #12 proposes "
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0"
If 13 pirates: #13 would get thrown overboard because the 7 of the first 12 not offered a coin will vote against him.
If 14 pirates: #14 proposes "
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0*, 0, 0, 0"  and the 5 offered coins plus #13 and #14 approve this.
If 15 to 17 pirates: these all get thrown overboard because the 9 of the first 14 not offered a coin will vote against them.
If 18 pirates: #18 proposes "
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, ..."  and the 5 offered coins plus #15 to #18 approve this.
If 19 to 25 pirates: these all get thrown overboard because the 13 of the first 18 not offered a coin will vote against them.
If 26 pirates: #26 proposes "
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, ..."  and the 5 offered coins plus #19 to #26 approve this.
If 27 to 41 pirates: these all get thrown overboard because the 21 of the first 26 not offered a coin will vote against them.
If 42 pirates: #42 proposes "
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, ..."  and the 5 offered coins plus #27 to #42 approve this.
If 43 to 73 pirates: these all get thrown overboard because the 37 of the first 42 not offered a coin will vote against them.
If 74 pirates: #74 proposes "
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, ..."  and the 5 offered coins plus #43 to #74 approve this.
If 75 to 100 pirates: these all get thrown overboard because the 69 of the first 74 not offered a coin will vote against them.

*Note that for 14 pirates above, the proposal could actually include 1 coin for any 5 odd numbered pirates from the first 12. Then for 18 pirates, the proposal could include 1 coin for any 5 of the first 14 pirates, even or odd, because those offered a coin should approve since they are not 100% certain to get one in the round with 14 pirates. The same is true for 26, 42, or 74 pirates.
Five Hats
A
Three wise men are lined up in single file, each wearing a white hat. They know there were 5 hats total, three white, and two black, but they can only see the hats on the men in front of them. They don't speak unless they figure out what color hat they have on. Who figures out first?
Pop Quiz
A
A teacher announces there will be a surprise quiz sometime during the week. The students argue it can't be on Friday because if the teacher waits until the last day it won't be a surprise anymore. Once they know it can't be Friday they argue by the same reasoning that it can't be Thursday either. What is wrong with this logic?
Answer: This inductive reasoning leads you to claim the surprise can't be on any day, and therefore doesn't actually differentiate any of them.
Darts
A
You throw two darts at a dart board, aiming for the center. The second lands farther from the center than the first. You then throw another dart at the board, aiming for the center. Assume your skill level is consistent. What are the chances that this third dart also lands farther from the center than the first?
Answer: 2/3. This is just another way of saying: what are the chances that your third dart is not the best.
Girl Babies
A
A large tribe obeys a strict reproductive custom. All families continue having children until they have a girl, and then they stop having more children. Assume it is equally likely for a given birth to produce a girl or boy, and assume families can have any number of children so they always do get one girl eventually. In the 10th generation, what is the expected ratio of males to females? Also, what is the expected population size of the 10th generation relative to the 1st?
Answer: The male to female ratio is 50/50. The odds of each new baby are always 50/50, and a rule for when families stop having children does not affect those odds.
The population size also stays the same, because there are 2 children per family on the average. They all have 1 girl, and the boy/girl ratio is 50/50 so they must also have an average of 1 boy.
Another way to calculate this is as follows: All families have 1 girl. Prior to that, 1/2 of the families also have at least one boy, 1/4 have another boy, 1/8 have another, etc. The sum of the series (1/2 + 1/4 + 1/8 + 1/16...) equals 1. So on the average its just 1 girl and 1 boy.
Hotel Bellboy
A
Three people check into a hotel. They pay $30 to the manager and go to their room. The manager finds out that the room rate is $25 and gives $5 to the bellboy to return. On the way to the room the bellboy reasons that $5 would be difficult to share among three people so he pockets $2 and gives $1 to each person. Now each person paid $10 and got back $1. So they paid $9 each, totaling $27. The bellboy has $2, totaling $29. Where is the remaining dollar
Answer: You wouldn't add the bellboys $2 to the $27, you would subtract it. They paid $27, the bellboy kept $2, and $25 was for the room.
Doctor Who
A
A father and his son are in a car crash. The father is killed instantly but the son is only injured and is taken to the hospital. He is rushed to the operating room, the doctor comes in, looks at the patient on the operating table, and says, "I can't operate on him, he's my son." How can this be?
Answer: The doctor is his mother.
Two Fathers and Two Sons
A
Two fathers and two sons are in a boat. One person falls overboard, but there are only two people left in the boat. How can this be?
Answer: There was a grandfather, father, and son. The father counts as both a father and a son.
Two Boys and a Boat
A
Two boys wish to cross a river. The only way to the other side is by boat, but the boat can only take one boy at a time. The boat can not return on its own and there are no ropes or similar tricks, yet both boys manage to cross using the boat. How?
Answer: The boys start on opposite sides of the river.
Defying Death
A thief is caught and sentenced to death, but the king allows him to make one last statement which will also determine his method of execution. He is to be hanged if his statement is true, or he is to be fed to lions if his statement is false. Somehow he manages to live. What did he say?
Answer: He said: "I will be fed to lions."
Non-Self Containing Sets
What is difficult about the set of all sets that do not contain themselves?
Answer: If this superset (of all sets that don't contain themselves) contains itself, then it shouldn't, and vice versa.
Manhole Covers
A
Why are manhole covers round?
Answer: So they don't fall in. A square cover nearly the same size and shape as the hole, for example, could fit into the hole diagonally.
Mirrors
Why do mirrors seem to flip things left-right but not up-down?
Answer: Mirrors actually flip things front-back. Flipping left-right and then rotating about a vertical axis gives the same transform. A "mirror image" is more easily perceived this way, probably because humans are left-right symmetrical. You could also think of this transform as flipping up-down and then rotating about a horizontal axis but this is harder to visualize unless you turn your face sideways first.
Centrifuge
A
Can you spin 5 samples in a 12-hole centrifuge, without it being out of balance?
Answer: Yes. You can independently balance 3, and then 2. Put 3 in equally spaced from each other, such as in slots 1, 5, and 9. Then put in the other 2 opposite each other, such as in slots 2 and 8.
1000 Doors
A
A thousand doors start closed. Someone walks along and changes the state of each door (opens or closes). A 2nd person changes the state of every 2nd door, and a 3rd person changes the state of every 3rd door. This continues until the 1000th person changes the state of the 1000th door. How can you know if the Nth door is now open or closed? (without simulating the whole thing)
Answer: The doors whose number equals a perfect square are open. Those with an odd number of factors, including 1 and the number, are open, and only perfect squares have an odd number of factors.
Three Dice
A
You roll three dice, and multiply the resulting numbers together. What are the chances that product is odd?
Answer: 1/8. All 3 must be odd for the product to be odd. 1/2 x 1/2 x 1/2 = 1/8
Two Dice at 7
A
If you roll two dice, what are the chances they add to 7? (This is a warm-up for the next problem.)
Answer: 1/6. There are 6x6=36 possible combinations and 6 of those give 7 (1+6, 2+5, 3+4, 4+3, 5+2, 6+1). Another way to think of it is for any number on the 1st dice, there is always one number on the 2nd dice that will give 7 so no matter what you roll first, you still have a 1/6 chance of getting 7 total.
Four Dice at 14
A
If you roll four dice, what are the chances they add to 14?
Answer: 146/1296 = 77/648 = 11.265%
This problem can be tedious to solve, but here is a way that isn't too bad. There are 6x6x6x6 = 1296 possible combinations for 4 dice, and we want to find how many of those will sum to 14. No matter what you roll for the 1st two dice, you can still get 14 in the end, so we can go through the possible results of the 1st two dice (2 to 12) and ask how many ways are there to get to 14 for each of those.
For the 2+12 case: there is only 1 way the 1st two dice can give 2 (1+1), and only 1 way the 2nd two dice can give 12 (6+6) so there is just 1 combination there. For the 3+11 case: there are 2 ways the 1st two dice can give 3 (1+2 or 2+1) and for each of those there are 2 ways the 2nd two dice can give 11 (6+5 or 6+5), so 2x2 combinations there.
For the 4+10 case: there are 3 ways the 1st two dice can give 4 (1+3, 2+2, 3+1), and 3 ways the 2nd two dice can give 10 (4+6, 5+5 6+4), so 3x3 combinations there.
For the 5+9 case: there are 4 ways the 1st two dice can give 5, and 4 ways the 2nd two dice can give 9, so 4x4 combinations there.
And so on for the 6+8, 7+7, 8+6, 9+5, 10+4, 11+3, and 12+2 cases.
When we add all these together we get 1x1 + 2x2 + 3x3 + 4x4 + 5x5 + 6x6 + 5x5 + 4x4 + 3x3 + 2x2 + 1x1 = 146 total ways to get 14 out of the 1296 total combinations.
Note that your chances of getting a 4 instead are just 1/1296 or 146 times less likely than getting a 14.

Meet in the Middle
A
You are negotiating to buy a Persian rug where they often overcharge tourists. You offer 1/2 the asking price, and the salesman says he can meet you in the middle at 3/4. You then offer to meet him in the middle again (between 1/2 and 3/4) and he does the same back to you again (between 5/8 and 3/4). What price would you arrive at if you continued like this forever?
Answer: 2/3 of the original asking price. You are offering: 1/2 + 1/8 + 1/32... and the salesman is reducing his price by 1/4 + 1/16 + 1/64... At each step the price is reduced by half the amount that your offer increased, so the final price should also be twice the amount of the final discount. (1/2 + 1/8 + 1/32...) = 2 x (1/4 + 1/16 + 1/64...) These have to sum to 1 so the final price is 2/3 (with a discount of 1/3).
Thanks to Arlo Sims for proposing this puzzle and its solution.
Alien Hats
A
You are among 10 humans abducted by aliens who will be given an intelligence test to determine if earth is worth saving. You will be lined up single file and each given a white or black hat, at random. Nobody will see the color of their own hat, nor can they see the hats on the people behind them, but they can see the hats on all the people in front of them. Then, one at a time, each person must guess the color of their own hat, starting with the person in the back who sees all the others, and ending with the person in the front who sees nothing. No other communication is allowed except the single guess "black" or "white" from each person. No delays or tone of voice signals are allowed. If anybody except the first person guesses wrong, everyone is killed and earth is destroyed. Fortunately you have some time before the test to discuss and agree on a strategy. Can you save the planet, and if so how?
Alien Hats
Answer: The first person can say "white" if they see an odd number of white hats in front of them or "black" for an even number. The 2nd person can then calculate the correct color of their hat: if the number of white hats they see has a different odd/even result, then theirs must be white. The others can each in turn adjust the original odd/even result based on what all the people behind them say (each "white" answer flips it) and then compare that to the number of white hats they see to figure out the correct color of their hat. Planet saved.
100 Prisoners and 100 Boxes
A
A room has 100 boxes labeled 1 to 100, containing the names of 100 prisoners, one name per box in a random order. These 100 prisoners visit the room one by one, and each is allowed to inspect up to 50 boxes, one after the other. If all the prisoners somehow each manage to find their own name in a box, they are all released. The prisoners may not change anything in the room or communicate any information to the others after entering the room. However they are allowed to meet ahead of time and devise a plan. Is there a strategy that allows all of the prisoners to find their names with some reasonable probability?
Answer: Number the prisoners 1 to 100. Each prisoner uses the following rule: First inspect the box matching your number. Then convert the prisoner's name found in that box to his number and inspect that box next. Repeat until you either find your own name or use up your 50 tries.
Amazingly this allows all of them to find their own names slightly more than 30% of the time! This consistent box searching order creates loops where a given name is certain to be within the loop of boxes being searched. If no loops happen to contain more than 50 boxes, all of them will succeed.

Ball Paths
A
        
A ball is dropped into the top of the stack of boxes as shown. The boxes are open on the top and bottom so if there are 2 boxes below, the ball can fall either to the left or right. How many possible paths are there from the top to the bottom box? (The ball never bounces back up, and motion within a box doesn't matter. A path is a unique sequence of boxes that the ball passes through.)
Answer: 70. The number of possible paths to any given box is the sum of the possible paths to each of the two boxes above it. There is only 1 possible path for each box on the top edges (all lefts, or all rights) and filling in numbers for each other box by summing its two neighbors above, gives 70 total possible paths for the bottom box.

        Some of you may recognize this as Pascal's triangle of binomial coefficients, but with the bottom corners missing.

Ball Paths 2
A
        
Similar to above, a ball is dropped into the top of the stack of boxes and falls down to the bottom box. For each level, when there are 2 boxes below, the ball falls randomly left or right with equal chances. (Assume the direction the ball came from the previous level does not affect the next bounce.) Two of the many possible paths from top to bottom are shown. Which of these paths is more likely, or are they equally likely?
Answer: The red path is more likely. It has 1/16 chances because there are 4 forks along the way, each with 1/2 chances of happening. 1/2 x 1/2 x 1/2 x 1/2 = 1/16. Once the ball gets to a box on the bottom left edge it has no option but to fall right towards the center. The green path has only 1/128 chances of happening because it has 7 forks along the way, each with 1/2 chances. The green path may look more "random" but that exact path is much less likely because the ball has more options when it stays away from the bottom edges.
Square of Bugs
A
Four bugs are on the corners of a 1 meter square. Each bug always faces the next bug (on the next clockwise corner). If they all walk forward at the same speed until they meet, how far does each bug travel?
Answer: 1 meter. A bug's movement remains perpendicular to the next bug's, so the total distance is the same as if the bug being chased was stationary. They start out 1 meter apart so that is the total distance traveled when they meet in the center.
Another solution method: They must meet in the center, and the distance from a corner to the center is 1/sqrt(2). The bugs always head at 45 degrees relative to the center, so they will travel a total of sqrt(2) times that distance. 1/sqrt(2) x sqrt(2) = 1
A Bee and Two Trains
A
Two trains are 30 miles apart, and travel towards each other at 5 mph and 10 mph. A bee starts at the slower train and flies at 25 mph to the other train. Each time it reaches a train it turns around and flies back to the other train again. What is the sum of the distances that the bee has flown when the trains meet?
Answer: 50 miles. The trains travel for 2 hours until they meet, and the bee flies at 25 mph the whole time, so he flies 50 miles. (Hope you didn't try to calculate each zig and zag!)
Backwards Bee and Two Trains
A
Two trains start end-to-end at the same point and travel away from each other at 5 mph and 10 mph. A bee also starts at the same point and flies back and forth at 25 mph between the ends of the moving trains. After 2 hours, where is the bee?
Answer: There is no way to know. Trick question.
Water Levels
A
You are on a boat in a small pond. You have a stone and a log in the boat. You throw the stone into the water. Does the water level in the pond rise, fall or stay the same? How about if you throw the log in?
Answer: The stone sinks and then displaces less water than when it was being floated by the boat, so the water level falls.
The log floats and continues to displace the same amount of water as its weight, so the water level stays the same.
Pieces of Stone
A
A farmer has a 40 lb stone that he uses to measure out bales of hay on a 2 sided balance. He loans it to a friend who accidentally breaks it into 4 pieces. Instead of being angry, the farmer is quite happy. He says to the friend, "you managed to break it into just the right 4 pieces that will now let me weigh any weight between 1 and 40." What are the weights of the 4 pieces?
Answer: 1, 3, 9, and 27. You can put multiple pieces on the scale to add their weights, or put pieces on the other side to subtract them.
Breaking Balls
A
You have 2 bowling balls that each breaks when dropped from the same height. You want to find the highest floor of a 100 story building from which these balls can be dropped without breaking. Devise an optimal procedure that can always locate that floor using not more than N drop tests. What is the smallest N can be?
Answer: You can do it in 14 drops. You can't use a normal divide-by-2 search here because once the first ball breaks you'll need to search all the untested floors below from bottom to top. To find the best strategy, work backwards from fewer floors:
1 drop allows you to test 1 floor.
2 drops can test 3 floors: Test the 2nd floor first. It it breaks, test the bottom floor with the other ball. If not, test the top floor with either ball.
3 drops can test 6 floors: Test the 3rd floor first. If it breaks test the bottom 2 floors in order with the other ball. If not, test the top 3 floors as described above.
4 drops can test 10 floors: Test the 4th floor first. If it breaks test the bottom 3 floors in order with the other ball. If not, test the top 6 floors as described above.
N drops allows you to test the number of floors equal to the sum of 1 to N. 14 drops can test 105 floors: Test the 14th floor first. If it breaks test the bottom 13 floors in order with the other ball. If not, test the 27th floor next (14+13), and so on.
For any given drop, the number of drops you'll need after that should be the same if that ball breaks or not (or sometimes they are off by 1 if your total is not an even sum-of-1-to-N).
1.  A farmer returns from the market, where he bought a she-goat, a cabbage and a wolf (what a crazy market :-). On the way home he must cross a river. His boat is small and won't fit more than one of his purchases. He cannot leave the she-goat alone with the cabbage (because the she-goat would eat it), nor he can leave the she-goat alone with the wolf (because the she-goat would be eaten).
How can the farmer get everything on the other side in this river crossing puzzle?
Take the she-goat to the other side. Go back, take cabbage, unload it on the other side where you load the she-goat, go back and unload it. Take the wolf to the other side where you unload it. Go back for the she-goat. That's it.
2. Three missionaries and three cannibals want to get to the other side of a river. There is a small boat, which can fit only two. To prevent a tragedy, there can never be more cannibals than missionaries together.
1 cannibal and 1 missionary there, missionary back. 2 cannibals there, 1 cannibal back. 2 missionaries there, 1 missionary and 1 cannibal back. 2 missionaries there, 1 cannibal back. This one cannibal takes the remaining cannibals to the other side.
3. Parents with two children - a son and a daughter - came to a wide river. There was no bridge there. The only way to get to the other side was to ask a fisherman if he could lend them his boat. However, the boat could carry only one adult or two children.
How does the family get to the other side and return the boat to the fisherman?
First go the children. Son comes back, and father goes on the other side to his daughter. Then daughter goes back to pick her brother up and they both go to the other side to the father. Son comes back to give the boat to mother who goes to the other side (to father and daughter). Daughter jumps in and goes to her brother so they can both return to their parents. Daughter gets off and son gives the boat back on the first side of the river to the fisherman, who goes on the other side. There the daughter jumps in and goes to her brother to take him back to parents where she (where the whole family meets at last) returns the boat to the fisherman.
The boat crossed the river 13 times.


What is restrict option in directive?

The restrict option in angular directive, is used to specify how a directive will be invoked in your angular app i.e. as an attribute, class...