Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Pearls in the Box solution in Clear category for Pearls in the Box by JimmyCarlos
from fractions import Fraction
# The benefits of using Fraction is that you get an exact answer.
# Recursion, each iteration taking one pearl
def iterate(b,w,movesLeft):
if movesLeft == 1:
return Fraction(w,b+w)
else:
return ( Fraction(b,b+w) * iterate(b-1,w+1,movesLeft-1)
+Fraction(w,b+w) * iterate(b+1,w-1,movesLeft-1))
def checkio(s,N):
b = s.count("b")
w = s.count("w")
return float(iterate(b,w,N))
Aug. 31, 2018