Sort by

recency

|

18 Discussions

|

  • + 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))
    
  • + 0 comments
    from fractions import Fraction
    urns = [[4,3],[5,4],[4,4]]
    red = []
    black = []
    for lst in urns:
        red.append(Fraction(lst[0],sum(lst)))
        black.append(Fraction(lst[1],sum(lst)))
    doub = []
    for i in range(len(red)-1):
        for j in range(i+1, len(red)):
            doub.append(red[i]*red[j])
    final = []
    for j in range(len(black)):
        final.append(doub[j]*black[len(black)-j-1])
    print(sum(final))
    
  • + 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)
    
  • + 0 comments
    X = ['r','r','r','r','b','b','b']
    Y = ['r','r','r','r','r','b','b','b','b']
    Z = ['r','r','r','r','b','b','b','b']
    
    matched = 0
    instance = 0
    
    for x in X:
        for y in Y:
            for z in Z:
                if ([x,y,z].count('r')==2) and ([x,y,z].count('b')==1):
                    matched += 1
                instance += 1
    
    print(str(matched//12)+"/"+str(instance//12))
    
  • + 0 comments

    Python 3 code

    from fractions import Fraction
    
    p1 = ['r']*4 + ['b']*3
    p2 = ['r']*5 + ['b']*4
    p3 = ['r']*4 + ['b']*4
    
    combo = []
    visited = 0
    
    for i in p1:
        for j in p2:
            for k in p3:
                temp = [i, j, k]
                count_r = temp.count('r')
                count_b = temp.count('b')
                if (count_r==2) and (count_b==1):
                    combo.append(temp)
                    
                visited += 1
    
    print(Fraction(len(combo), visited))