Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Pearls in the Box by roenke
def checkio(marbles, step):
def prop(b, w, level):
if b < 0 or w < 0:
return 0.
if level == 0:
return w / (b + w)
return w / (w + b) * prop(b + 1, w - 1, level - 1) + b / (w + b) * prop(b - 1, w + 1, level - 1)
black, white = marbles.count('b'), marbles.count('w')
return float(format(prop(black, white, step - 1), '.2f'))
June 2, 2016
Comments: