• + 0 comments

    I tried to do it both pythonically and with clear decipherability from the problem description. Pythonically meant, in this context, making good use of the unpacking operators.

    from math import gcd
    from itertools import product, combinations
    
    b1 = (*'r'*4, *'b'*5)
    b2 = (*'r'*3, *'b'*7)
    total = [(*a, *b) for a, b in product(combinations(b1, 1), combinations(b2, 2))]
    n = len([_ for _ in total if _.count('b') == 2])
    d = len(total)
    factor = gcd(n, d)
    print(n//factor, '/', d//factor, sep='')