-
-
Save yashk/9ff9bdeff02696a140100b3d1e01a9cc to your computer and use it in GitHub Desktop.
Calculate the blast radius of a shuffle shard
This file contains hidden or 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 sys | |
def factorial(n): | |
if n == 0: | |
return 1 | |
else: | |
return n * factorial(n - 1) | |
def choose(n, m): | |
return factorial(n) / (factorial(m) * factorial(n - m)) | |
def overlap(n, m, o): | |
return (choose(m, o) * choose(n - m, m - o)) / choose(n, m) | |
def usage(): | |
print "shard.py n m" | |
print " n: The total number of elements" | |
print " m: The number of elements per shard" | |
if __name__ == "__main__": | |
if len(sys.argv) != 3: | |
usage() | |
try: | |
n = int(sys.argv[1]) | |
m = int(sys.argv[2]) | |
except: | |
usage() | |
if m > n: | |
usage() | |
print "n = ", n | |
print "m = ", m | |
for i in range(0, m + 1): | |
print 'overlap: %-4d %0.20f' % (i, overlap(float(n), float(m), float(i)) * 100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment