Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
probability + recursion solution in Clear category for Pearls in the Box by imtiaz.rahi
def probability(w: int, b: int, step: int):
wp = w / (w + b)
if step == 1: return wp
return wp * probability(w-1, b+1, step-1) + ((1-wp) * probability(w+1, b-1, step-1))
def checkio(marbles: str, step: int) -> float:
return round(probability(marbles.count('w'), marbles.count('b'), step), 2)
Sept. 24, 2019