Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Recursive solution in Creative category for Pearls in the Box by vit.aborigen
def checkio(marbles: str, step: int) -> float:
b,w = marbles.count('b'), marbles.count('w')
return 1 - round(bintree(b, w, step), 2)
def bintree(b, w, depth):
if depth == 1:
return b/(b+w)
if not w:
return bintree(b-1, w+1, depth-1)
elif not b:
return bintree(b+1, w-1, depth-1)
return bintree(b-1, w+1, depth-1) * b/(b+w) + bintree(b+1, w-1, depth-1) * w/(b+w)
Oct. 14, 2018
Comments: