Showing posts with label puzzles. Show all posts
Showing posts with label puzzles. Show all posts
Sunday, July 26, 2009
induction too
My lame attempt at this.
[Hat tip to xkcd - images from Fetishes, No Pun Intended, Voynich Manuscript, Designated Drivers]
Wednesday, June 03, 2009
Induction
PS: For information, read Josephine's problem (Cheating Husbands Puzzle) over here.
[Hats off to xkcd - images from Hobby and Numerical Sex Positions]
Tuesday, March 03, 2009
sudoku evil
Sometime back, I had solved this sudoku. After filling in the few blanks in blue, it did not budge. So I had assumed the positions of the 1-3 pair in the top right square.
With any sudoku, you should not have to assume. I tried it again and found it to be true.
I was stuck again at the same state. In the bottom right square, 3 and 5, even though possible in different blocks, paired. After that, it fell apart.
Saturday, July 12, 2008
Burning fuses
Interesting puzzle.
Light both ends of first fuse and only one of the second. When the first fuse burns off completely, light the other end of the second.
[Hat tip to PIE]
You are given two fuses and a lighter. When lit, each fuse takes exactly 1 hour to burn from one end to the other. The fuses do not burn at a constant rate, though, and they are not identical. In other words, you may make no assumptions about the relationship between the length of a section of fuse and the time it has taken or will take to burn. Two equal lengths of fuse will not necessarily take the same time to burn. Using only the fuses and the lighter, measure a period of exactly 45 minutes?
Here is a clue:
If you light both ends of a fuse, it would burn completely in half the time.
Light both ends of first fuse and only one of the second. When the first fuse burns off completely, light the other end of the second.
[Hat tip to PIE]
Fibonacci
What is the upper and lower bound of Fibonacci series when we use int variables?
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 (from wiki)
I would code the Fibonacci series as follows.
The issue is that
Coming back to the bounds.
fib(n>1) = fib(n-1) + fib(n-2)
fib(n=0) = 0, fib(n=1) = 1
An approximation for the lower bound:
fiblower(n) = 2 * f(n-1)
For n=32, we get 2^32 *f(1). Lower bound for n is 32.
By some observation you can see that for the upper bound:
fibupper(n) = 3/2 * f(n-1)
For n=64 (with little calculation), we get above 2^32. Upper bound for n is 64.
Anyways, the ratio of the Fibonacci numbers tend to the golden ratio Φ (Φ = 1.6180339887...).
i.e. f(n) ~ Φ * f(n-1)
[Hat tip to AN]
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 (from wiki)
I would code the Fibonacci series as follows.
fib(n)
x = -1, y = 1
for n times:
z = x+y
print z
x = y, y = z
The issue is that
x is not unsigned and you miss the 32nd bit i.e. I cannot print above 2^31-1.Coming back to the bounds.
fib(n>1) = fib(n-1) + fib(n-2)
fib(n=0) = 0, fib(n=1) = 1
An approximation for the lower bound:
fiblower(n) = 2 * f(n-1)
For n=32, we get 2^32 *f(1). Lower bound for n is 32.
By some observation you can see that for the upper bound:
fibupper(n) = 3/2 * f(n-1)
For n=64 (with little calculation), we get above 2^32. Upper bound for n is 64.
Anyways, the ratio of the Fibonacci numbers tend to the golden ratio Φ (Φ = 1.6180339887...).
i.e. f(n) ~ Φ * f(n-1)
[Hat tip to AN]
Wednesday, July 09, 2008
Birthday paradox
With 23 people in a room, there is a 50% chance that there would be at least two people with same birthday.
Questions around this would be like if someone bets with you that in a room of n people, for each person with different birthday, he gets $x and you get $y otherwise. Would you bet?
First, it says any two people and not with just you (and so the paradox). There are 23 people and so 23C2 i.e. 253 pairs and not just 22 pairs.
e = event that at least two people have same birthday.
e' = event that all people have different birthdays.
And p(e) = 1 - p(e')
For p(e'):
For 1 person to have different birthday,
p(e') = 365/365 = 1
For 2 persons to have different birthdays,
p(e') = (364/365) * 365/365 = 365! / (365 -2)! * 1/365^2
For n persons to have different birthdays,
p(e') = 365! / (365 -n)! * 1/365^n
And p(e) = 1 - 365! / (365 -n)! * 1/365^n
With n as 23, p(e) = 50.7%
p(e) is 100%, when n = 366.
Update: The probability of you having the same birthday as someone else is (n-1)/365 and you would need 134 people for ~50% and 366 for 100%.
Questions around this would be like if someone bets with you that in a room of n people, for each person with different birthday, he gets $x and you get $y otherwise. Would you bet?
First, it says any two people and not with just you (and so the paradox). There are 23 people and so 23C2 i.e. 253 pairs and not just 22 pairs.
e = event that at least two people have same birthday.
e' = event that all people have different birthdays.
And p(e) = 1 - p(e')
For p(e'):
For 1 person to have different birthday,
p(e') = 365/365 = 1
For 2 persons to have different birthdays,
p(e') = (364/365) * 365/365 = 365! / (365 -2)! * 1/365^2
For n persons to have different birthdays,
p(e') = 365! / (365 -n)! * 1/365^n
And p(e) = 1 - 365! / (365 -n)! * 1/365^n
With n as 23, p(e) = 50.7%
p(e) is 100%, when n = 366.
Update: The probability of you having the same birthday as someone else is (n-1)/365 and you would need 134 people for ~50% and 366 for 100%.
Tuesday, July 01, 2008
Monty Hall problem
Heard about the Monty Hall problem? The problem has a interesting history with Marilyn vos Savant.
We have two events which are below.
e1. You choose a door.
e2. The host chooses a door with goat.
We are interested in p(e1) and p(e2): p(wining) = p(e1) * p(e2)
p(wining) = 1/3
1. p(wining by not switching) = *1/3 = 1/9
2. p(wining by switching) = *2/3 = 2/9
p(not wining) = 2/3
1. p(not wining by switching) = *1/3 = 2/9
2. p(not wining by not switching) = *2/3 = 4/9
So to answer the question, it is in your advantage to switch. In short, you would have probabilities like 1/n², (n-1)/n², (n-1)/n², (n-1)²/n².
Now, here is the interesting part for n doors. Try this with 100 doors, you choose one door (e1) and the host always opens up 98 doors (n-2) revealing goats (e2) and then offers you to switch.
For 100 doors, probabilities are 1/100², 99/100², 99²/100² i.e.
p(wining) = 1/100
1. p(wining by not switching) = *1/100 = 1/100²
2. p(wining by switching) = *99/100 = 99/100²
p(not wining) = 99/100
1. p(not wining by switching) = *1/100 = 99/100²
2. p(not wining by not switching) = *99/100 = 99²/100²
You see the impact of switching. By switching, you increase your odds of wining by a factor or 99 which is n-1 (comparing 1/100² and 99/100²). Also note that by switching, you can win or lose by the same probability (99/100²).
There is another variation for n doors, where the host opens up p doors (p <= n-2). In that case, p(wining by switching) = (n-1) * 1/n * 1/(n-1-p). Note that (n-1-p) is 1 when p=n-2 i.e. there is only one door to switch to and p(wining by switching) comes to (n-1)/n. When p is less than n-2, there are additional doors to switch to (i.e. with 1 additional door, p(wining by switching) decreases by factor 2), so p(wining by switching) decreases by (n-1-p) factor. When p=0 (e2 is where host opens no doors), you are back where you started - 1/n. When p = n-1, well, the host isn't going to give you the car like that easily, is s/he? The point is, when p decreases, the advantage by switching reduces.
I like the case of p = n-1. And the car is Lexus IS.
Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what's behind the doors, opens another door, say No. 3, which has a goat. He then says to you, "Do you want to pick door No. 2?" Is it to your advantage to switch your choice? (Whitaker 1990)Below is the explicit version which makes clear that the host does not offer the choice in his own best interest etc.
Suppose you're on a game show and you're given the choice of three doors. Behind one door is a car; behind the others, goats. The car and the goats were placed randomly behind the doors before the show. The rules of the game show are as follows: After you have chosen a door, the door remains closed for the time being. The game show host, Monty Hall, who knows what is behind the doors, now has to open one of the two remaining doors, and the door he opens must have a goat behind it. If both remaining doors have goats behind them, he chooses one randomly. After Monty Hall opens a door with a goat, he will ask you to decide whether you want to stay with your first choice or to switch to the last remaining door. Imagine that you chose Door 1 and the host opens Door 3, which has a goat. He then asks you "Do you want to switch to Door Number 2?" Is it to your advantage to change your choice? (Krauss and Wang 2003:10)This is one of those counter-intuitive problems. The problem with 3 doors is the most common one and you can find the explanation to the solution on wiki. I will just summarize it below.
We have two events which are below.
e1. You choose a door.
e2. The host chooses a door with goat.
We are interested in p(e1) and p(e2): p(wining) = p(e1) * p(e2)
p(wining) = 1/3
1. p(wining by not switching) = *1/3 = 1/9
2. p(wining by switching) = *2/3 = 2/9
p(not wining) = 2/3
1. p(not wining by switching) = *1/3 = 2/9
2. p(not wining by not switching) = *2/3 = 4/9
So to answer the question, it is in your advantage to switch. In short, you would have probabilities like 1/n², (n-1)/n², (n-1)/n², (n-1)²/n².
Now, here is the interesting part for n doors. Try this with 100 doors, you choose one door (e1) and the host always opens up 98 doors (n-2) revealing goats (e2) and then offers you to switch.
For 100 doors, probabilities are 1/100², 99/100², 99²/100² i.e.
p(wining) = 1/100
1. p(wining by not switching) = *1/100 = 1/100²
2. p(wining by switching) = *99/100 = 99/100²
p(not wining) = 99/100
1. p(not wining by switching) = *1/100 = 99/100²
2. p(not wining by not switching) = *99/100 = 99²/100²
You see the impact of switching. By switching, you increase your odds of wining by a factor or 99 which is n-1 (comparing 1/100² and 99/100²). Also note that by switching, you can win or lose by the same probability (99/100²).
There is another variation for n doors, where the host opens up p doors (p <= n-2). In that case, p(wining by switching) = (n-1) * 1/n * 1/(n-1-p). Note that (n-1-p) is 1 when p=n-2 i.e. there is only one door to switch to and p(wining by switching) comes to (n-1)/n. When p is less than n-2, there are additional doors to switch to (i.e. with 1 additional door, p(wining by switching) decreases by factor 2), so p(wining by switching) decreases by (n-1-p) factor. When p=0 (e2 is where host opens no doors), you are back where you started - 1/n. When p = n-1, well, the host isn't going to give you the car like that easily, is s/he? The point is, when p decreases, the advantage by switching reduces.
I like the case of p = n-1. And the car is Lexus IS.
Subscribe to:
Posts (Atom)



