Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Fast solution using functools.lru_cache solution in Clear category for Pearls in the Box by swagg010164
from functools import lru_cache
@lru_cache(maxsize=1024)
def rec(white, black, step):
if step == 1:
return white / (black + white)
if white == 0:
return rec(white + 1, black - 1, step - 1)
if black == 0:
return rec(white - 1, black + 1, step - 1)
return white / (black + white) * rec(white - 1, black + 1, step - 1) + \
black / (black + white) * rec(white + 1, black - 1, step - 1)
def checkio(marbles: str, step: int) -> float:
return round(rec(marbles.count('w'), marbles.count('b'), step), 2)
March 14, 2020