Skip to content

Instantly share code, notes, and snippets.

@Khrol
Created June 30, 2020 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Khrol/a66818c7624ee844cbebb70bd26e3ea1 to your computer and use it in GitHub Desktop.
Save Khrol/a66818c7624ee844cbebb70bd26e3ea1 to your computer and use it in GitHub Desktop.
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