Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Pearls in the box solution in Uncategorized category for Pearls in the Box by capback250
from fractions import Fraction
def checkio(pearls, step):
queqe = [[pearls, 1]]
for i in range(step-1):
tempQ = []
for curr in queqe:
if len(set(curr[0])) == 1:
tempQ.append(['b'*(len(curr[0])-1) + 'w', curr[1]]) if 'b' in curr[0] else tempQ.append(['w'*(len(curr[0])-1) + 'b', curr[1]])
else:
tempQ.append([curr[0].replace('w', 'b', 1), curr[1] * Fraction(curr[0].count('w'), len(curr[0]))])
tempQ.append([curr[0].replace('b', 'w', 1), curr[1] * Fraction(curr[0].count('b'), len(curr[0]))])
queqe = tempQ
return round(float(sum([Fraction(x[0].count('w'), len(x[0])) * x[1] for x in queqe])), 2)
Feb. 4, 2016