• + 0 comments
    from fractions import Fraction
    
    def urns(a):
        prob = [Fraction(x[0], sum(x)) for x in a]
        prob_c = [1 - x for x in prob]
        
        n = len(a)
        ans = 0
        for i in range(n):
            p = prob_c[i] * prob[(i + 1) % n] * prob[(i + 2) % n]
            ans += p
        return ans
    
    b =  [[4, 3], [5, 4], [4, 4]]
    print(urns(b))