Created
June 7, 2019 18:04
-
-
Save CamDavidsonPilon/28341c5781d63f452f11ba4e78e89b68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MAX = 114 | |
MIN = 22 | |
def falling_factorial(n, k): | |
""" | |
computes (n) * (n-1) * ... * (n-(k-1)) | |
""" | |
running_product = n | |
for p in range(n-1, n-k, -1): | |
running_product *= p | |
return running_product | |
def P_max_le_ub_min_ge_lb(N, n, lb, ub): | |
return falling_factorial(ub - lb + 1, n) / falling_factorial(N, n) | |
def P_max_eq_ub_min_eq_lb(N, n, lb, ub): | |
if ub > N: | |
return 0 | |
return (P_max_le_ub_min_ge_lb(N, n, lb, ub) - | |
P_max_le_ub_min_ge_lb(N, n, lb, ub - 1) - | |
P_max_le_ub_min_ge_lb(N, n, lb + 1, ub) + | |
P_max_le_ub_min_ge_lb(N, n, lb+1, ub-1)) | |
running_max = 0 | |
arg_running_max = (None, None) | |
for N in range(114, 200): | |
for n in range(2, N+1): | |
p = P_max_eq_ub_min_eq_lb(N, n, MIN, MAX) | |
if p > running_max: | |
running_max = p | |
arg_running_max = (N, n) | |
print(p, arg_running_max) | |
print(N) | |
# Our estimate of the number of tanks seen is 9 | |
# Using the UMVUE formula | |
tanks = MAX*(1 + 1/arg_running_max[1]) + 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment