Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second - Expected pearl count solution in Clear category for Pearls in the Box by carel.anthonissen
def checkio(marbles, step):
w_count,t_count = marbles.count('w'),len(marbles) # Assign the white pearl count and the total pearl count
for i in range(step-1): # Conduct a step-by-step update of the expected white pearl count
w_count = ((w_count+1)*(1-w_count/t_count) + # Expected contribution of an increasing white pearl count
(w_count-1)*(w_count/t_count)) # Expectad contribution of a decreasing white pearl count
return w_count/t_count # Return the expected white pearl count as a proportion of the total pearl count
June 6, 2017