You will write the binomial probability, a cumulative probability and a search for the number of trials needed to reach a target chance. The checker uses exact fractions.
The idea. For trials with success probability , . "At most " adds the terms from to . To reach a target chance of at least one success, increase until is at least the target.
Your tasks.
binomial(n, p, k). Use comb(n, k) from the math module.at_most(n, p, k). Add binomial(n, p, j) for j from to k.smallest_n(p, target). Return the smallest n for which the chance of at least one success is at least target.Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…