Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Recursion with rounding solution in Creative category for Pearls in the Box by mindaugas.dadurkevicius
def returning(result, now):
if now == 1:
return round(result,2)
return result
def checkio(marbles: str, step: int, certanty = 1, now = 1):
if now == step:
return returning(marbles.count('w')/len(marbles)*certanty, now)
else:
if 'w' in marbles and 'b' in marbles:
return returning(checkio(marbles.replace('w','b', 1), step, marbles.count('w')/len(marbles)*certanty, now+1) + checkio(marbles.replace('b','w', 1), step, marbles.count('b')/len(marbles)*certanty, now+1), now)
elif 'w' in marbles:
return returning(checkio(marbles.replace('w','b', 1), step, certanty, now+1), now)
else:
return returning(checkio(marbles.replace('b','w', 1), step, certanty, now+1), now)
Sept. 4, 2018