Last active
November 18, 2022 07:59
-
-
Save clar/7a59006e161266fa2e845233e5bc30d4 to your computer and use it in GitHub Desktop.
prob.py
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
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)) |
Author
clar
commented
Nov 18, 2022
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment