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.
defsolve(a,b,c):#what is the maximum possible value of x that guarantees that x+y<C?x_val_guarantee_success=c-b#and what is the probability of getting that x value?p_guaranteed_success=max([min([x_val_guarantee_success,a])/a,0])#so it might be that we never get that value, but we could do.middle_group_lbound=max([x_val_guarantee_success,0])#next;whatistheminimumpossiblevalueofxthatguaranteesx+y>=C,failure?#that'll be when x>=C even without considering Ymiddle_group_ubound=min([c,a])p_guaranteed_failure=max([0,(a-c)/a])#now, the probability of sitting somewhere in the middlep_contingent_on_y=1-p_guaranteed_success-p_guaranteed_failure#now, the probability of the limits on each sidep_lower=(c-middle_group_lbound)/b#ok and now at the upper limit, i.e., x<C#proportion of possible values of y for which x+y<C#y_value_needed_at_p_higher<-C-min(x_val_guarantee_failure,A)p_higher=(c-middle_group_ubound)/bp_total=p_guaranteed_success+sum([p_lower,p_higher])/2*p_contingent_on_y+p_guaranteed_failure*0if(p_total==1):retval="1/1"else:retval=str(Fraction(p_total).limit_denominator(max_denominator=10000000000))return(retval)
Seems that getting the fractions right is really tricky--a couple of my answers were off a tiny bit, and I'm not sure whether it's because the math I used leaves me with a wrong answer, or if the fractional answers are wrong.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Random number generator
You are viewing a single comment's thread. Return to all comments →
I tried:
Seems that getting the fractions right is really tricky--a couple of my answers were off a tiny bit, and I'm not sure whether it's because the math I used leaves me with a wrong answer, or if the fractional answers are wrong.