Sort by

recency

|

11 Discussions

|

  • + 0 comments

    My Python solution with explanation:

    import math
    
    # setup situation
    bag1 = ['r']*4 + ['b']*5    # 1 pick
    bag2 = ['r']*3 + ['b']*7    # 2 picks
                                # b b r
    
    # initialize counting variables
    numerator = 0
    denominator = 0
    
    # collect event occurrences
    for X in bag1:  # 1 pick from bag1
        
        for Y1 in bag2:  # 1 pick from bag2
            bag2reduced = bag2.copy()  # create a COPY of bag2
            bag2reduced.remove(Y1)  # remove already picked element from COPY of bag2
            
            for Y2 in bag2reduced:  # 1 pick from EDITED bag2
                tup = (X, Y1, Y2)  # event
                
                if all([tup.count('r') == 1,
                        tup.count('b') == 2]):  # conditions of interest
                    numerator += 1
                
                denominator += 1
    
    gcd = math.gcd(numerator, denominator)
    
    numerator //= gcd
    denominator //= gcd
    
    print(f'{numerator}/{denominator}')
    
  • + 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))
    
  • + 0 comments

    Python 3 code

    from fractions import Fraction
    
    bag1 = ['r']*4 + ['b']*5
    bag2 = ['r']*3 + ['b']*7
    
    combo = []
    visited = 0
    
    for i in bag1:
        for e, j in enumerate(bag2):
            for k in bag2[e+1:]:
                temp = [i, j, k]
                if (temp.count('r') == 1) and (temp.count('b') == 2):
                    combo.append(temp)
                
                visited += 1
                
    print(Fraction(len(combo), visited))
    
  • + 0 comments

    what is the problem i couldn't understand please help me: import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*; public class Prob {

    public static void main(String[] args) {int x[]; int y[]; Scanner in = new Scanner(System.in);

    for(int i=0;i<2;i++) { x[i]=in.nextInt(); } for(int i=0;i<2;i++) { y[i]=in.nextInt(); } int prob1,prob2; prob1 = x[1] * (y[1]+1); prob2 = (x[0]+x[1])*((y[0]+y[1])+1);

    System.out.println(prob1+"/"+prob2); } }

  • + 0 comments

    Here's how I approached to the solution

    We can take 1 ball from Bag1 and 2 from Bag2

    Probability of 2 black and 1 red

    From Bag1 either we get the red or black ball From Bag2 either we get both ball black or one red and one black. (Incase, if Bag1 got a black ball)

    1st Possibility

    Bag1: 4/9 (Red Ball) Bag2:7/10 (1st Black Ball taken out) -> 6/9 (2nd Black Ball)

    2nd Possibility

    Bag1: 5/9 (Black Ball) Bag2: 7/10 (1st Black Ball) -> 3/9 (2nd Red Ball)

    3rd Possibility

    Bag1: 5/9 (Black Ball) Bag2: 3/10 (1st Red Ball ) -> 7/9 (2nd Black Ball)

    Multiplying and combining all possibility Possibility#1 + Possibility#2 + Possibility#3 = 7/15