Skip to content

Instantly share code, notes, and snippets.

@gemasergey
Created August 4, 2017 09:03
Show Gist options
  • Save gemasergey/b800585a04c5395cb87162a5fd50ffc9 to your computer and use it in GitHub Desktop.
Save gemasergey/b800585a04c5395cb87162a5fd50ffc9 to your computer and use it in GitHub Desktop.
Super-progressive dialing method
#!/usr/bin/env python3.5
from scipy.special import binom
import sys, math
def to_be_dialed(p, k):
p = float(p)
k = int(k)
n = k
while True:
summa = []
i =1
while i <= (n - k):
a = i / (k+i)
b = binom(n, (k+1))
c = p ** (k+i)
d = (1 - p) ** (n - k - i)
summa.append(a * b * c * d)
i += 1
print(n, summa)
if math.fsum(summa) > 0.1:
return (n - 1)
else:
n += 1
if __name__ == '__main__':
num = to_be_dialed(sys.argv[1], sys.argv[2])
print("to be dialed: {}".format(num))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment