• + 0 comments

    I tried:

    def solve(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; what is the minimum possible value of x that guarantees x+y>=C, failure?
        #that'll be when x>=C even without considering Y
        middle_group_ubound = min([c,a])
        p_guaranteed_failure = max([0,(a-c)/a])
        #now, the probability of sitting somewhere in the middle
        p_contingent_on_y = 1-p_guaranteed_success-p_guaranteed_failure
        #now, the probability of the limits on each side
        p_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)/b
    
        p_total  = p_guaranteed_success+sum([p_lower,p_higher])/2*p_contingent_on_y+p_guaranteed_failure*0
    
    
        if(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.