Skip to content

Instantly share code, notes, and snippets.

@clar
Last active November 18, 2022 07:59
Show Gist options
  • Save clar/7a59006e161266fa2e845233e5bc30d4 to your computer and use it in GitHub Desktop.
Save clar/7a59006e161266fa2e845233e5bc30d4 to your computer and use it in GitHub Desktop.
prob.py
import math
from re import S
def choose(n, k):
return math.factorial(n) // math.factorial(k) // math.factorial(n-k)
def prob(n, k, p):
return math.exp(math.log(p) * k + math.log(1-p) * (n-k) + math.log(choose(n, k)))
def probge(n, k, p):
return sum([prob(n, i, p) for i in range(k, n+1)])
# def probge(n, k, p):
# total = 0
# for i in range(k, n+1):
# s = prob(n, i, p)
# total += s
# return total
r = 1.5/32
D = 300000
committee = int(r*D)
print(committee)
half = int((committee + 1) / 2)
for p in [0.47, 0.48, 0.49, 0.5, 0.51]:
print(committee, half, p)
print(p, probge(committee, half, p))
@clar
Copy link
Author

clar commented Nov 18, 2022

(venv) ➜  pyscripts python prob.py
14062
14062 7031 0.47
0.47 5.673022879793059e-13
14062 7031 0.48
0.48 1.085159654612776e-06
14062 7031 0.49
0.49 0.009051311715550547
14062 7031 0.5
0.5 0.5033641766950481
14062 7031 0.51
0.51 0.9913525704207236

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment