Skip to content
DeepForgeby svx
All problems
HardProbabilitypr-088

Irwin-Hall CDF

Problem

Cumulative distribution function of the sum of n independent Uniform(0, 1) variables at x:

F(x) = (1 / n!) * sum over k of (-1)^k * C(n, k) * (x - k)^n

with the sum taken over k from 0 to floor(x). Return 0.0 for x <= 0 and 1.0 for x >= n.

Hint

Inclusion-exclusion on the constraints u_i >= 1.

Test cases

case 1
in: [1,0.5]
expected: 0.5
case 2
in: [2,1]
expected: 0.5
case 3
in: [3,1.5]
expected: 0.5
case 4
in: [2,2.5]
expected: 1
case 5
in: [2,-1]
expected: 0
Starter codePython
import math


def irwin_hall_cdf(n, x):
    # Your code here
    pass

5 test cases · run your code against them in the editor