Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Maths - with proof solution in Uncategorized category for Pearls in the Box by Juge_Ti
def checkio(seq, n):
r = len(seq)
w = seq.count('w')
return round(1/2 + (1-2/r)**(n-1) * (w/r-1/2), 2)
# Proof :
#
# Let r be the total number of pearls.
#
# Let X(n) be the number of white pearls in the nth step. We have :
#
# (1) P(X(n+1)=k) = (r-k+1)/r * P(X(n)=k-1) + (k+1)/r * P(X(n)=k+1)
#
# Let C(n) be the color of the pearl taken out of the box in the nth step.
#
# The probability we are looking for is p(n)= P(C(n)='white').
#
# By the law of total probability, we have :
#
# (2) p(n) = sum of P(C(n)='white'|X(n)=k) * P(X(n)=k)
#
# = sum of k/r * P(X(n)=k)
#
# From (1) and (2) we get p(n+1) = 1/r + (1-2/r) * p(n).
#
# And we have p(1)= w/r where w is the number of white pearls at the beginning.
#
# Hence p(n) = 1/2 + (1-2/r)**(n-1) * (w/r-1/2).
Jan. 8, 2014
Comments: