PIXELBANKv9.1.0
Menu

pass@k Estimator

Problem Statement

Estimate pass@k, the probability that at least one of k sampled generations passes, given n total samples of which c passed. This is the standard unbiased HumanEval estimator.

Background

The unbiased estimator is

pass@k=1−(n−ck)(nk)\text{pass@}k = 1 - \frac{\binom{n-c}{k}}{\binom{n}{k}}

If n - c < k (fewer failures than k), pass@k is exactly 1.0 (every draw of k must include a pass). Compute it stably.

Your Task

def pass_at_k(n, c, k):

Return the pass@k estimate as a float rounded to 6 decimals.

Input Format

  • n (int total samples), c (int correct), k (int), with 0 <= c <= n, 1 <= k <= n.

Output Format

  • A float rounded to 6 decimals.

Sample

print(pass_at_k(5, 1, 1))

Output:

0.2

Example:

Input:
print(pass_at_k(5, 1, 1))
Output:
0.2
Reasoning:
  • Check for guaranteed pass: Compare the number of failures (n−cn - c) against kk. With n=5n=5 and c=1c=1, there are 5−1=45 - 1 = 4 failures. Since 4≥14 \ge 1 (kk), it is not guaranteed that a pass is included in the sample, so we proceed to the probabilistic calculation.
  • Calculate the failure probability: The term (n−ck)(nk)\frac{\binom{n-c}{k}}{\binom{n}{k}} represents the probability that all kk samples are failures. For k=1k=1, this simplifies to the ratio of failures to total samples: 5−15=45=0.8\frac{5-1}{5} = \frac{4}{5} = 0.8.
  • Compute the pass probability: Subtract the failure probability from 1 to find the probability of at least one pass: 1−0.8=0.21 - 0.8 = 0.2.
  • Format the result: Round the result to 6 decimal places, yielding 0.2000000.200000, which is represented as 0.2.
  • The final output is 0.2

Constraints:

  • If n - c < k, return 1.0.
  • Otherwise 1 - C(n-c,k)/C(n,k); compute with a stable product.
  • Round to 6 decimals.
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.