A workshop receives large batches of bolts. Instead of checking every bolt, an inspector picks n bolts at random and tests them. The batch is accepted when at most c of the tested bolts are faulty; otherwise it is sent back.
If a fraction r of the bolts in a batch is faulty, each tested bolt is faulty with probability r, independently of the others (the batches are so large that removing a few bolts changes nothing).
Write acceptance_curve(n, c, rates) that returns a list with one float per value in rates: the probability that a batch with that faulty rate is accepted. Plotted against the rate, these numbers show how well the inspection separates good batches from bad ones.
Examples
Input: n = 10, c = 1, rates = [0.0, 0.1, 0.3]
Output: [1.0, 0.7360989291, 0.1493083459]
Explanation: with r = 0.1, P(0 faulty) = 0.9^10 = 0.3487 and P(1 faulty) = 10 · 0.1 · 0.9^9
= 0.3874, so the batch is accepted with probability 0.7361.
Input: n = 50, c = 2, rates = [0.01, 0.05, 0.1]
Output: [0.9861827291693992, 0.540533122719514, 0.11172875634634728]
Constraints
1 <= n <= 500,0 <= c <= n0 <= len(rates) <= 100, every rate between0and1inclusive- floats are compared with a tolerance of
1e-6
Goals
- Recognise a count of independent yes/no outcomes as binomial
- Compute binomial probabilities with math.comb
- Add up probabilities of several counts to get P(K <= c)