• + 0 comments
    from itertools import combinations
    from fractions import Fraction
    
    n = 3
    k = 2
    
    p_r = [Fraction(4,7), Fraction(5,9), Fraction(4,8)]
    p_b = [Fraction(3,7), Fraction(4,9), Fraction(4,8)]
    total = Fraction(0,1)
    
    for i,j in combinations(range(n), k):
        remaining_option = next(x for x in range(n) if x not in (i, j))
        total += p_r[i] * p_r[j] * p_b[remaining_option]
    
    print(total)