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.
frommathimportgcddefprob(red_1,black_1,red_2,black_2):# Total outcomestotal_1=red_1+black_1total_2=red_2+black_2total_outcomes=total_1*(total_2*(total_2-1)// 2)# Favorable outcomes# Black from Bag 1, 1 red + 1 black from Bag 2BRB=black_1*(red_2*black_2)#RedfromBag1,2blacksfromBag2RBB=red_1*(black_2*(black_2-1)// 2)favorables=BRB+RBBdivisor=gcd(favorables,total_outcomes)num=favorables// divisorden=total_outcomes// divisorreturnf"{num}/{den}"
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 →