Skip to content

Instantly share code, notes, and snippets.

@jimtje
Created January 13, 2020 13:38
Show Gist options
  • Save jimtje/57a140964602429568ca04bbaf1713a0 to your computer and use it in GitHub Desktop.
Save jimtje/57a140964602429568ca04bbaf1713a0 to your computer and use it in GitHub Desktop.
def calc_prop_length(run_length, total_length, success_probability):
P = [None for i in range(0, total_length + 1)]
fail_probability = 1 - success_probability
for i in range(0, run_length):
P[i] = 0
P[run_length] = success_probability ** run_length
for i in range(run_length, total_length):
P[i + 1] = P[i] + (1 - P[i - run_length]) * fail_probability * (success_probability ** run_length)
return P[total_length]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment