Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Pearls in the Box by yukirin
from collections import deque
def checkio(marbles, step, result=0.0):
count = len(marbles)
box = deque([[marbles, 1, 1]])
while box:
pearls, rate, n = box.popleft()
if n == step:
result += (pearls.count('w') / count) * rate
continue
bs, ws = pearls.count('b'), pearls.count('w')
if ws:
box.append([pearls.replace('w', 'b', 1), (ws / count) * rate, n + 1])
if bs:
box.append([pearls.replace('b', 'w', 1), (bs / count) * rate, n + 1])
return round(result, 2)
July 20, 2015
Comments: