Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Tree-recursive solution in Clear category for Pearls in the Box by nooodl
def p(white, black, step):
pwhite = float(white) / (white + black)
pblack = 1.0 - pwhite
if step == 1:
return pwhite
else:
p1 = p(white - 1, black + 1, step - 1) * pwhite
p2 = p(white + 1, black - 1, step - 1) * pblack
return p1 + p2
def checkio(marbles, step):
return p(marbles.count('w'), marbles.count('b'), step)
Aug. 22, 2014
Comments: