Skip to content

Instantly share code, notes, and snippets.

@dmarzzz
Created May 25, 2023 00:17
Show Gist options
  • Save dmarzzz/d81dd17cf27a70dee394f6fb651445ef to your computer and use it in GitHub Desktop.
Save dmarzzz/d81dd17cf27a70dee394f6fb651445ef to your computer and use it in GitHub Desktop.
orobability of controlling >50% of an N-size committee
from decimal import Decimal
import math
def calculate_summation(N, p):
p = Decimal(p)
result = Decimal(0)
for k in range(math.floor(N/2), N+1):
term = Decimal(math.comb(N, k)) * (p**k) * ((1-p)**(N-k))
result += term
return float(result)
# Testing the function
N = 9000
p = 0.40
result = calculate_summation(N, p)
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment