We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
# Enter your code here. Read input from STDIN. Print output to STDOUTimportfractionsfromitertoolsimportcombinationsfromitertoolsimportproductBag1=['r']*4+['b']*5Bag2=['r']*3+['b']*7Bag2_comb=list(combinations(Bag2,2))matched=0total=len(Bag1)*len(list(combinations(Bag2,2)))forxinlist(product(Bag1,Bag2_comb)):if[x[0],x[1][0],x[1][1]].count('b')==2and[x[0],x[1][0],x[1][1]].count('r')==1:matched+=1print(fractions.Fraction(matched,total))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 2: Basic Probability Puzzles #4
You are viewing a single comment's thread. Return to all comments →