Created
June 30, 2020 19:07
-
-
Save Khrol/a66818c7624ee844cbebb70bd26e3ea1 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
from math import comb | |
def chance(k, n, K, N): | |
return comb(K, k) * comb(N - K, n - k) / comb(N, n) | |
def fits_in_delta_prob(lower, upper, n, K, N): | |
result = 0 | |
for x in range(n + 1): | |
ratio = x / n | |
if lower <= ratio <= upper: | |
result += chance(x, n, K, N) | |
return result | |
def probabilities(N, delta): | |
x15 = 0.071 | |
x20 = 0.433 | |
return list(map(lambda K: (K, round(fits_in_delta_prob(x15 - delta, x15 + delta, 15, K, N) * fits_in_delta_prob(x20 - delta, x20 + delta, 20, K, N) * 100, 2)), range(N))) | |
def solve(N, delta): | |
answer = probabilities(N, delta) | |
m = answer[0] | |
for a in answer: | |
if a[1] > m[1]: | |
m = a | |
return m | |
solve(10000, 0.07) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment