Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Recursion solution in Clear category for Pearls in the Box by obone
def checkio(marbles: str, step: int) -> float:
def proba(b: int, w: int, step: int) -> float:
if step == 1:
return w / (b + w)
return b * proba(b - 1, w + 1, step - 1) / (b + w) \
+ w * proba(b + 1, w - 1, step - 1) / (b + w)
return round(proba(marbles.count('b'), marbles.count('w'), step), 2)
June 27, 2019