Quick puzzle: how long to get to heaven?
mindyourdecisions.com
mindyourdecisions.com
This is math team math all the way: if you were asking any question I might have to think, but since it involves repetitive calculations of expected value (probability times result), infinite length, and a trick allowing hand calculability, I know it has to decompose to sum of an infinite geometric series somehow.
Some variants left as an exercise to the reader:
a) Three door game as above with doors where A = heaven, B = 2 days + retry, and C = 4 days plus retry. If you get the lesson, this should be trivial.
b) Write a Satan's version of the three door game, where the rules look "simple enough" but the expected time to reach heaven is not finite. (This would be a great extra credit problem for a high school advanced math course -- and full points and a smiley face for "Doors A, B, and C all say 'come back tomorrow'.")
You have a 1/3 chance of picking the direct door, so on average it will take you three tries to catch it.
1 try == 1 day delay expected (1/3 x 0 + 1/3 x 1 + 1/3 x 2).
3 tries, 3 days.
import random
def one():
n = 0
while True:
k = random.randint(0,2)
if k==0: return n
n += k
def many(k):
return sum(one() for i in range(n)) / float(n)
[many(1000) for i in range(10)]
many(100000)
will make it pretty easy to guess what the right answer is.The previous-but-one posting on the same blog has a distinctly more difficult question: repeatedly pick independent random numbers uniform on [0,1]; stop when your latest number is smaller than some previous one; what's the average number of numbers you have to pick? Exercise for the reader: provide the appropriate definition of one() to make the calculation above work. It's only a few lines.
(Mathematically expert readers will be able to solve both these problems rigorously and quickly without simulating. But if such a problem comes up in a context where you actually care about the answer you'd do well to do the simulation anyway, since it's an easy way to check your reasoning.)
I calculated that from a scale of 0 and 1, we have a 0.33 chance of going in in 0 days.
The probability of going in within 1 day is equal to the probability of choosing the second door (0.33) multiplied to the probability of choosing the first door the second time (0.33). 0.33 * 0.33 is equal to 0.1089, so we have a 10% chance of getting in with 1 days.
To get in in 2 days, we would have to choose the second door, and then the first door. Again, this is another 10%
At this point I thought that we have a 53% chance of getting in within two days (33% + 10% + 10%), and 47% of getting in with more than 2 days.
The probability of getting in within 3 days is 0.33 * 0.33 * 0.33, which is around 3%. Considering that the probability of getting in within 4 days would be 1% (0.33 * 0.33 * 0.33 * 0.33), I somehow imagined that of the remaining 47% of chances of getting in within more than two days, the 75% was represented by the probability of getting in within 3 days. The 75% of 47% is 35.2%, which is slightly higher than the chance of getting in within 0 days. The answer is 3.
Given that I lack math background, I wonder if my way of solving this problem is correct (hopefully someone can follow my reasoning).
Nope, sorry :-). First, you missed a bunch of possibilities (e.g., you said that to get in after 2 days you need to choose 2,0, but you could choose 1,1,0 instead; you said that to get in after 3 days you need to choose 1,1,1,0, but you could also choose 1,2,0 or 2,1,0). Second, at best what you've got is an estimate. Third, the question wasn't "what's the most likely time it takes", which I think is what you've tried to work out, but "how long on average". (The most likely time is actually 0 days.)
I've run into a few problems like this. The simplest solution exploits the property that there is an ordering on the states, so each "later" state can depend only on "earlier" states or itself. A more general EV problem would require Gaussian elimination instead of DP. Fun stuff, all in all.
Whether he expected heaven to involve any experience of time for its human inhabitants, I don't know.