• + 0 comments
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    import fractions
    from itertools import combinations
    from itertools import product
    
    
    Bag1 = ['r']*4 + ['b']*5
    Bag2 = ['r']*3 + ['b']*7
    
    Bag2_comb = list(combinations(Bag2,2))
    
    matched = 0
    total = len(Bag1) * len(list(combinations(Bag2,2)))
    
    for x in list(product(Bag1, Bag2_comb)):
        if [x[0], x[1][0], x[1][1]].count('b')==2 and [x[0], x[1][0], x[1][1]].count('r')==1:
            matched += 1
    
    print(fractions.Fraction(matched, total))