I have the following Python equation:
def E(r, b):
if r == 0:
return 0
elif b == 0:
return r
else:
return max(0, (r/(r+b))*[1+E(r-1,b)]+(b/(r+b))*[E(r,b-1)-1])
print E(1,1)
The recursion does not seem to work. For E(1, 1) the mathematical equation should return 1/2. However I am getting 0. And for E(2, 2), I am getting an error, when mathematically it should be 2/3.
from __future__ import division
def E(r, b):
if r == 0:
return 0
elif b == 0:
return r
else:
return max(0, (float(r)/float(r+b))*[1+E(r-1,b)]+(float(b)/float(r+b))*[E(r,b-1)-1])
print E(1,1)
I made the following adjustments but still ran into errors: "TypeError: can't multiply sequence by non-int of type 'float'"