All problems
Probability of At Least One Fixed Point
Problem
Probability that a uniformly random permutation of n items has at least one fixed point:
P = 1 - D(n) / n!
where D(n) is the derangement count. The value approaches 1 - 1 / e. Return 0.0 for n <= 0.
Hint
Complement of the hat-check no-match probability.
Test cases
case 1
in: [1]
expected: 1
case 2
in: [2]
expected: 0.5
case 3
in: [3]
expected: 0.6666666666666667
case 4
in: [4]
expected: 0.625
Starter codePython
import math
def probability_at_least_one_fixed_point(n):
# Your code here
pass4 test cases · run your code against them in the editor