Instantly share code, notes, and snippets.

Embed
What would you like to do?
Calculate the blast radius of a shuffle shard
i mport 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
print " n: The total number of elements"
print " m: The number of elements per shard"
print
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
print
for i in range(0, m + 1):
print 'overlap: %-4d %0.20f' % (i, overlap(float(n), float(m), float(i)) * 100)
@rwrife

This comment has been minimized.

Show comment
Hide comment
@rwrife

rwrife Aug 29, 2018

It the extra space in "import" supposed to be there?

rwrife commented Aug 29, 2018

It the extra space in "import" supposed to be there?

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