You are digging holes to find a treasure. Each hole contains the treasure according to probability 0.05. What is the probability of find the treasure after digging less than 25 holes? There is only one treasure.
In [4]:
p = 0.05
psum = 0
for i in range(1,25):
psum += p * (1 - p)**(i - 1)
print('The probability of finding the treasure in between 1 and 24 holes is {:.2%}'.format(psum))
Digging a hole takes 30 minutes. How much time will give at least a 99% probability of finding the treasure.
In [10]:
p = 0.05
psum = 0
for i in range(1,1000):
psum += p * (1 - p)**(i - 1)
if psum >= 0.99:
break
time = 30 * i / 60
print('After {:.1f} hours, there will be a {:.2%} of finding the treasure'.format(time, psum))
You manage a hotel and have free umbrellas ready for guests so they can lounge on the beach. Historically, an average of nine umbrellas are requested each day. You would like to have enough umbrellas such that there is only a one in one thousand probability of you running out of umbrellas. How many umbrellas do you require?
In [14]:
from math import factorial, exp
mu = 9
psum = 0
for i in range(100):
psum += exp(-mu) * mu**i / (factorial(i))
if psum > (1 - 1 / 1000):
break
print('{} umbrellas will be sufficient with {:.5} probability.'.format(i, psum))
Siggi, my puppy, needs to urinate on average every 2 hours. If I leave him home for 6 hours, what is the probability that he will not urinate in the house?
In [17]:
p = 1 - exp(-6 / 2)
print('Using the previously derived equation, the probability is {:.3} that he will not urinate in the house'.format(1 - p))
You are trying to find players for a chess tournament at UR. A given student at UR has a probability of $0.07$ of knowing how to play chess and wanting to participate in the tournament. If you ask 20 students, what is the expected number of participants you will have for your tournament?
In [41]:
print('{} students'.format(20 * 0.07))
What is the probability that after asking 20 students you will have 3 players for your tournament?
In [42]:
p = factorial(20) / (factorial(17) * factorial(3)) * 0.07**3 * (1 - 0.07)**17
print('The probability is {:.3}'.format(p))
What is the probability that after asking 20 students you will have 3 or more players for your tournament?
In [43]:
p = 0.07
N = 20
psum = 0
for i in range(3, N + 1):
psum += factorial(N) / (factorial(N - i) * factorial(i)) * p**i * (1 - p)**(N - i)
print('The probability is {:.3}'.format(psum))
What is the most likely number of participants?
In [45]:
import numpy as np
from scipy.special import binom
p = 0.07
N = 20
x = np.arange(0, N + 1)
Px = binom(N, x) * p**x * (1 - p)**(N - x)
i = np.argmax(Px)
print('The most likely value is {} with probability {}'.format(x[i], Px[i]))