Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Strange feeling solution in Creative category for Pearls in the Box by MrPod
def checkio(marbles, step):
pr, new = {marbles: 1}, {}
for i in range(step - 1):
for j in pr:
a, b = [''.join(sorted(j.replace('bw'[i], 'wb'[i], 1))) for i in (0, 1)]
for k, m in {a: 'b', b: 'w'}.items():
new[k] = new.get(k, pr[j] * j.count(m) / len(j)) + (pr[j] * j.count(m) / len(j) if k in new else 0)
pr, new = new, {}
return sum(map(lambda i: i.count('w') * pr[i] / len(i), pr))
April 17, 2018
Comments: