Showing posts with label puzzle. Show all posts
Showing posts with label puzzle. Show all posts

The Fork in the Road

A logician vacationing in the South Seas finds himself on an island inhabited by two proverbial tribes of liars and truth-tellers. Members of one tribe always tell the truth, members of the other always lie. He comes to a fork in a road and has to ask a native bystander which branch he should take to reach a village. He has no way of telling whether the native is a truth-teller or a liar. The logician thinks a moment, then asks one question only. From the reply he knows which road to take. What question does he ask?
(source: My Best Mathematical and Logic Puzzles By Martin Gardner)

Solution:

If we require that the question be answerable by "yes" or "no" there are several solutions, all exploiting the same basic gimmick. For ex, the logician points to one of the roads and says to the native,
1. "If I were to ask you if this road leads to the village, would you say 'yes'?" The native is forced to give the right answer, even if he is a liar! If the road does lead to the village, the liar would say "no" to the direct question, but as the question is put, he lies and says he would respond "yes." Thus the logician can be certain that the road does lead to the village, whether the respondent is a truth-teller or a liar. On the other hand, if the road actually does not go to the village, the liar is forced in the same way to reply "no" to the inquirer's question.

2. "Of the two statements, 'You are a liar' and 'This road leads to the village,' is one and only one of them true?" Here again, a "yes" answer indicates it is the road, a "no" answer that it isn't regardless of whether the native lies or tells the truth.

Twist: Suppose logician knows that 'pish' and 'tush' are the native words for 'yes' and 'no' but has forgotten which is which, though otherwise he can speak the native language, He can still determine which road leads to the village:
He points to one of the roads and asks, 'If I asked you whether the road I am pointing to is the road to the village would you say pish?'

The Fork in the Road

A logician vacationing in the South Seas finds himself on an island inhabited by two proverbial tribes of liars and truth-tellers. Members of one tribe always tell the truth, members of the other always lie. He comes to a fork in a road and has to ask a native bystander which branch he should take to reach a village. He has no way of telling whether the native is a truth-teller or a liar. The logician thinks a moment, then asks one question only. From the reply he knows which road to take. What question does he ask?
(source: My Best Mathematical and Logic Puzzles By Martin Gardner)

Solution:

If we require that the question be answerable by "yes" or "no" there are several solutions, all exploiting the same basic gimmick. For ex, the logician points to one of the roads and says to the native,
1. "If I were to ask you if this road leads to the village, would you say 'yes'?" The native is forced to give the right answer, even if he is a liar! If the road does lead to the village, the liar would say "no" to the direct question, but as the question is put, he lies and says he would respond "yes." Thus the logician can be certain that the road does lead to the village, whether the respondent is a truth-teller or a liar. On the other hand, if the road actually does not go to the village, the liar is forced in the same way to reply "no" to the inquirer's question.

2. "Of the two statements, 'You are a liar' and 'This road leads to the village,' is one and only one of them true?" Here again, a "yes" answer indicates it is the road, a "no" answer that it isn't regardless of whether the native lies or tells the truth.

Twist: Suppose logician knows that 'pish' and 'tush' are the native words for 'yes' and 'no' but has forgotten which is which, though otherwise he can speak the native language, He can still determine which road leads to the village:
He points to one of the roads and asks, 'If I asked you whether the road I am pointing to is the road to the village would you say pish?'

The Returning Explorer

An old riddle runs as follows. An explorer walks one mile due south, turns and walks one mile due east, turns again and walks one mile due north. He find himself back where he started. He shoots a bear. What color is the bear? The time-honoured answer is: "White," because the explorer must have started at the North Pole. But not long ago someone made the discovery that the North pole is not the only starting point that satisfies the given conditions! Can you think of any other spot on the globe from which one could walk a mil south, a mile east, a mile north and find himself back at his original location?(source: My Best Mathematical and Logic Puzzles By Martin Gardner)

Solution:

Us there any other point on the globe, besides the North Pole, from which you could walk a mile south, a mile east, and a mile north and find yourself back at the starting point? Yes indeed; not just one point but an infinite number of them! You could start from any point on a circle drawn around the south pole at a distance slightly more than 1 + 1/2Pi miles ( 1.16 miles ) from the Pole, the distance is "slightly more" to take into account the curvature of the earth. After walking a mile south, your next walk of one mile east will take you on a complete circle around the Pole, and the walk one mile north from there will then return you to the starting point. Thus your starting point could be any one of the infinite points on the circle with a radius of about 1.16 miles from south pole. You could also start at points close to the Pole, so that the walk east woule carry you just twice around the Pole, or three time, and so on.

How many smokes?

Mr. Puffem, a heavy smoker for many years, finally decided to stop smoking altogether. "I'll finish the twenty-seven cigaretees I have left," she said to herself, "and never smoke another one."
It was Mrs. Puffem's practice to smoke exactly two-thirds of each cigarette. It did not take her long to discover that with the adi of some cellophane tape she could stick three butts together to make a new cigarette. With 27 cigarettes on hand, how many cigarettes can she smoke before she gives up the weed forever?

Solution:


After smoking 27 cigarettes, she patched together the butts to make 9 more, and after smoking these, she had enough butts for 3 more smokes; then with the final 3 butts she made one final cigarette, total : 40 cigarettes

The Colored Socks

Ten Red socks and ten blue socks are all mixed up in a dresser drawer. The twenty socks are exactly alike except for their color. The room in in pitch darkness and you want two matching socks. What is the smallest number of socks you must take out of the drawer in order to be certain that you have a pair that match? (source: Entertaining Mathematical Puzzles By Martin Gardner, Anthony Ravielli)

Answer:


Many people (including me) initially (and incorrectly )solved this puzzle as follows:
* Initially I pull out a sock, and this could be Red / Blue.
* Then to match the color of the first sock, we pull out (10 + 1) socks.

But if we read the question carefully, it simply says, "pair that match" and nothing about the
color, so all we need is to pull out just three socks.

Transportation of Bananas

There are 2 cities A and B, dist. between them is 1000 Km
we have 3000 bananas in city A and a elephant can carry max 1000 bananas at
any given time and it needs to eat a banana every 1 Km.

How Many Max. No. of bananas one can transfer to city B?

Note : the elephant cannot go without bananas to eat.




One possible solution is to transport the banana in stages or intervals


for 200 kms we have,
A 200 B 200 C 200 D 200 E 200 F
|--------|--------|--------|--------|--------|

A to B
------
-> 2000, 800
<- 2000, 600
-> 1000, 1400
<- 1000, 1200
-> 0 , 2000

distance left = 800

B to C
--------
-> 1000, 800
<- 1000, 600
-> 0, 1400

distance left = 600

C to D
-------
-> 400, 800
<- 400, 600
-> 0, 800

distance left = 400

Move from D to F , leaving 400 bananas.


for, 250 kms we have,
A 250 B 250 C 250 D 250 E
|--------|--------|--------|--------|

A to B
------
-> 2000, 750
<- 2000, 500
-> 1000, 1250
<- 1000, 1000
-> 0 , 1750

distance left = 750

B to C
------
-> 750 , 750
<- 750 , 500
-> 0 , 1000

distance left = 500

Go directly from C to E (500 kms) leaving 500 bananas

for, 300, we have
A 300 B 300 C 300 D 100 E
|--------|--------|--------|--------|

A to B
-------
-> 2000, 700
<- 2000, 400
-> 1000, 1100
<- 1000, 800
-> 0, 1500

distance left = 700

B to C
------
-> 500, 700
<- 500, 400
-> 0 , 600

distance left = 400

travel C to E, leaving only 200 bananas

Using the above scheme, we can transport a max of 500 bananas for intervals of 250,
this is probably not the best solution, and using dynamic programming we can find the
best solution.



Solders and dog

There is a column of soldiers fifty feet long. At the end of the line
there is a dog. The dog begins to run forward at exactly the same time
that the column begins to march forward. The dog runs to the head of the
column and then, without loosing any time he turns back and and runs
towards the rear of the column. He gets to the end of the line of
soldiers just as the column advances 50 feet. What is the distance
covered by the dog? (Assume that both the dog and the soldiers travel at
constant speeds.)

Answer:


when the dog ran on one way, the solders had marced 25 feet, and dog travelled 75 feet,
and by the time it could com back, the solders had marched another 25 feet, and dog travelled 25 feet.
so in total 100 feet

sum of digits puzzle

Let the letters: A, B, C, D, E, F, G, H, and I be representative of the
numbers 1, 2, 3, 4, 5, 6, 7, 8, 9 in no particular order. If we let
A+B+C=C+D+E=E+F+G=G+H+I=13, then what must E be?


A + B + C
+
D
+
E + F + G
+
H
+
I


Answer:


start from the maximum value = 9
and it can only be combined with 1, 3
so we have,
(1, 3, 9)

take the second maximum value = 8
possible tuples,
(1, 4, 8)
(2, 3, 8)

take the third max value = 7
(1, 5, 7)
(2, 4, 7)

take the third max value = 6
( 2, 5, 6 )
( 3, 4, 6 )

now, only C, E, F are common,
so,

Option I:

9 + 3 + 1
+
8
+
4 + 7 + 2
+
5
+
6

This is a perfectly valid arrangement

Option II:

9 + 1 +[3]
+
8
+
2 + 7 + 4
+
6
+
[3]

which is an invalid arrangement

So the required answer is 4.


Robots and Beacon

Two robots are each standing on a beacon, on a line of infinite length.
They both execute the same code. Write the code to have them collide.
Only use these commands:
SKIPNB - skip the next line of code if not on a beacon
MVR - move right one step
MVL - movel eft one step
JMP - goto label in the code
hint: have both robots move to the right in a loop. if a robot passes a
beacon, double its speed.




Three cases:

|--B--------R--------R-----|

|--R--------R--------B-----|

|--R--------B--------R-----|

Make the robots osciallate ( left to right ) so that the step
increases in each pass.

Hens, eggs, days

If a hen and a half lay an egg and a half in a day and a half then how many hens will it take to lay six eggs in six days?



no of hens directly propotional to eggs and inversely propotional to days

x 1.5 6
--- = ----- x ----
1.5 6 1.5
^^^ ^^^
days eggs

x = 1.5


Deck of 52 cards, two players

The rules of a card game (having 52 cards) played between two peole are:- they will turn over two cards at a time. If both the cards are Black they will go the first player's pile and if both are Red they they will go to the second player's pile. If one is Red and one Black then both the cards will simply be discarded.

The process of turning over two cards at a time is repeated till all the 52 cards are exhausted. Whoever is having more number of cards in their pile wins the game. In case of tie the first player is declared winner. What's the chance of second player winning the game?

Answer:


case I : 26B, 26R => tie, first player wins
case II : 26 Red, 26 Black => tie, first player wins
case III: The order of Red and Black cards are jumbled.
so we cards will cancel out each other and go into no man's pile and
the remaining cards will get equally distributed between the players,
resulting in a tie, and again the first player wins.

So the probability of the second player winning is zero

Chameleons and Changing Colors

There are 13 Red, 15 Green, and 17 Blue Chameleons at some point of time. Whenever two Chameleons of the different colors meet both of them change their color to the third color. Is it ever possible for all Chameleons to become of the same color? Why?


The difference in the numbers make it impossible.

Trailing zeros in 100!

What is the trailing number of zeros in 100!



Just compute zeros in , n * 8 * 10
we choose 8 because that is the max even num,
that produces the max num of zeros.
----------------------
Zeros
----------------------
(5 * 8 * 10) = 2
(15 * 18 * 20) = 2
(25 * 28 * 30 ) = 3
(35 * 38 * 40) = 2
(45 * 48 * 50 ) = 3
(55 * 58 * 60 ) = 2
(65 * 68 * 70) = 2
(75 * 78 * 80 ) = 3
(85 * 88 * 90) = 2
(95 * 98 * 100) = 3


crystal balls and the floor from which they break

There are two identical crystal balls and one needs to find out which is the maximum floor in a 100 storey building from where the balls can fall before they break. In the most efficient way, what will be the maximum number of drops required to find the right floor in any possible scenario? The balls are allowed to be broken (if required) while finding the right floor.


Solution 1 (Constant interval, not optimal):


import sys

min_drops = 100
min_interval = 1
for interval in range(1,50):
drops = 100/interval + max(100%interval, interval-1)
print "interval " , interval , " drops " , drops
if drops < min_drops:
min_drops = drops
min_interval = interval

print "min_interval ", min_interval, " min_drops ", min_drops


Solution 2 (increasing interval, not optimal):
seq = (1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 100)
count(seq) = 14.
worst case = 14 + 8 = 22


Solution 3 (decreasing interval, optimal, best solution):
14, 27, 39, 50, 60, 69, 77, 84, 90, 95, 100

The advantage with decreasing interval is that, when the crystal ball breaks
the number of trails required to determine the floor at which it breaks gets
smaller everytime.,

One method to decrease the interval is to find a number n, such that
∑n >= no_of_floors,
and then start from interval n, n+n-1, n+n-2 , .... 100
so when the ball breaks at 100, the number of trails required is the difference
b/w previous floor and current floor.

we have ∑n = n(n+1)/2 >= 100
solving the above equation gives, n = 14
so we will test from:
#14, #(14 + 14 - 1 = 27), #(27 + 14 - 2 = 39), #(39 + 14 - 3 = 50), #(50 + 14 - 4 = 60), #(60 + 14 - 5 = 69), #(69 + 14 - 6 = 77), #(77 + 14 - 7 = 84), #(84 + 14 - 8 = 90), #(90 + 14 - 9 = 95), #(95 + 14 - 10 = 99), and finally from #100.

probability of taking the correct seat

100 passengers are waiting to board a flight having 100 seats. Each of them is having a ticket with a particular seat number which is same as their number in the queue. Unfortunately the first person in the queue is little crazy and he can occupy any random seat. Now, all other passengers will see if their seat is occupied by that crazy guy or not? If not, then they will be seated on their own seat numbers otherwise they will also look for a free random seat to sit on. This continues. What's the probability that the 100th person gets his own seat to sit on?

Answer:

1. Probability of the first person taking his seat = 1/2 (no its not 1/100, since there are only two chances , either he may sit in the correct place or he may not)
2. Probability of the second person taking this correct seat = 1/2
....
so even for the 100th person, it will be 1/2

Average salary without disclosing salary

Three coworkers would like to know their average salary. how can they do it, without disclosing their own salaries?

Solution:

Let's say the three co-workers are A, B, and C and their individual salaries are Sa, Sb, and Sc respectively. For knowing the average of their salaries without disclosing their own salaries to each other, they follow these steps:-

* A adds a random amount, say Ra to his own salary and gives that to B (B won't be able to know A's salary as he has added a random amount known to him only). In this case, B will receive the figure (Sa + Ra) from A.
* B does the same and gives the final amount to C (without showing that to A). Now C will get the figure (Sa + Ra + Sb + Rb).
* C does the same and gives the final figure to A (without showing it to B). Now, A will receive the figure (Sa + Ra + Sb + Rb + Sc + Rc).
* Now A subtracts his random amount and gives the final figure to B (without showing that to C). B will now receive the figure (Sa + Sb + Rb + Sc + Rc).
* B subtracts his random amount and gives the final figure to C (without showing it to A). C will receive the figure (Sa + Sb + Sc + Rc).
* C subtracts his random amount and then the figure becomes (Sa + Sb + Sc). It's shown to everyone and by they get to know the average simply by dividing this figure by 3.

Very good puzzle

shaking hands with a pair of gloves

Bill Gates is about to give 3 distinct awards, 1 each, to 3 different
distinguished developers. He needs to hand 1 award to each developer and
then shake the developer's hand. However, all 4 people involved in this
ceremony have a separate disease. If Bill shakes Developer 1's hand
(without protection), Bill will contract Developer 1's disease and
Developer 1 will contract Bill's disease (and so on for all of the
others). The only protection Bill has available at this ceremony is a
pair of normal, plain gloves. The ceremony cannot be delayed and Bill
must think of a quick solution before he embarrasses himself. Given this
information, how can Bill proceed?

Answer:

1. Wear one glove on another, and shake hand with first developer.
2. Remove the first glove and shake hand with the second developer.
3. Now, reverse the first glove and wear it on the second glove, and shake hand.

Hats puzzle

There are 3 black hats and 2 white hats in a box. Three men (we will
call them A, B & C) each reach into the box and place one of the hats
on his own head. They cannot see what color hat they have chosen. The
men are situated in a way that A can see the hats on B & C's heads, B
can only see the hat on C's head and C cannot see any hats. When A is
asked if he knows the color of the hat he is wearing, he says no. When B
is asked if he knows the color of the hat he is wearing he says no. When
C is asked if he knows the color of the hat he is wearing he says yes
and he is correct. What color hat and how can this be? There is no play
on words and there are no tricks.

Answer:



A will know only if, B and C are wearing White hats.
i.e B W W
and since A does not know, B and C are wearing either of,
B B
W B
B W

Now B would know what he is wearing if it C was wearing W. (last option)
Since B does not know, C knows for sure that he is wearing W


Bridge crossing problem

There are four men who would all like to cross a rickety old bridge.
(Perhaps it is more accurate to say that they'd like to get to the
other side.) The old bridge will only support 2 men at a time, and it is
night time, so every crossing must use the one flashlight that they all
share. The four men each have different walking speeds; the fastest each
of them can cross is 1 minute, 2 minutes, 5, minutes, and 10 minutes. If
they pair up, since they must share the flashlight, they can only cross
in the time that it would take the slower of the two. Given that the
shortest time to get them all across is 17 minutes total, how should
they all cross?




1, 2 go together, drops 2 and comes back, taking 3 minutes
(1,2)-------> 2
<------

5,10 go together, taking 10 minutes
(5,10)------> 2, 5, 10

Now, 2 comes back with the light
and takes 1 to the other side, taking 4 minutes

Note, its efficient to club 5,10.

Winners in a game

There is a new game in which 3 person play each other and only one wins. If 81 person participated in the tournament give a quick reply that how many matches will be played to decide the winner.
Answer:


Its logarithmic,
27 27 27
| | |
9 9 9 = 27
| | | +
3 3 3 = 9
| | | +
1 1 1 = 3
+
1
-------------------
i=3
∑ i = 81
i=0
-------------------



\ / \ /
9 9
\ /