Skip to content

Instantly share code, notes, and snippets.

@pellaeon
Created June 14, 2015 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pellaeon/27e6a65c68e2cfcc0a85 to your computer and use it in GitHub Desktop.
Save pellaeon/27e6a65c68e2cfcc0a85 to your computer and use it in GitHub Desktop.
from math import *
from decimal import *
S=20
lo=Decimal(5)
lh=Decimal(2)
u=Decimal(1)
def p0(y):
sum1=Decimal(0)
for i in range(0,y):
i=Decimal(i)
sum1+=((lo+lh)**i)/(factorial(i) * u**i)
sum2=Decimal(0)
for i in range(y+1,20):
sum2+=((lo+lh)**y * lh**(i-y))/(factorial(i) * u**i)
return Decimal(1)/(sum1+sum2)
def p(i,y):
i=Decimal(i)
if 0<=i and i<=y:
return (((lo+lh)**i)/(factorial(i) * u**i)) * p0(y)
elif i>y and i<=20:
return (((lo+lh)**y * lh**(i-y))/(factorial(i) * u**i)) * p0(y)
def bo(y):
sum1=Decimal(0)
for i in range(y,20):
sum1+=p(i,y)
return sum1
for x in range(0,20):
y=20-x
BO=bo(y)
BH=p(20,y)
print x,y,BO,BH
print "=========="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment