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 Olpag
def checkio(marbles, step):
def get_prob(marbles, step):
amount = len(marbles)
white_prob = marbles.count('w') / amount
black_prob = 1 - white_prob
if step == 1:
return white_prob
else:
white = white_prob * get_prob(marbles.replace('w', 'b', 1), step - 1)
black = black_prob * get_prob(marbles.replace('b', 'w', 1), step - 1)
return white + black
return round(get_prob(marbles, step), 2)
Feb. 26, 2019
Comments: