Skip to content
DeepForgeby svx
All problems
HardProbabilitypr-044

Inclusion-Exclusion Three Events

Problem

Inclusion-exclusion probability of the union of three events.

P(A union B union C) = P(A) + P(B) + P(C) - P(A and B) - P(A and C) - P(B and C) + P(A and B and C).

Hint

Add singles, subtract pairs, add back the triple intersection.

Test cases

case 1
in: [0.5,0.4,0.3,0.2,0.15,0.12,0.06]
expected: 0.79
case 2
in: [0.5,0.5,0.5,0.25,0.25,0.25,0.125]
expected: 0.875
case 3
in: [0,0,0,0,0,0,0]
expected: 0
case 4
in: [1,1,1,1,1,1,1]
expected: 1
case 5
in: [0.3,0.2,0.1,0,0,0,0]
expected: 0.6
Starter codePython
def inclusion_exclusion_three_events(p_a, p_b, p_c, p_ab, p_ac, p_bc, p_abc):
    # Your code here
    pass

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