All problems
Percolation Open Neighbor Probability
Problem
In site percolation each edge from a site is open independently with probability p. Return the probability that a site of the given degree has at least one open neighbor:
P = 1 - (1 - p)^degree.
Return 0.0 for negative degree or p outside [0, 1].
Hint
Complement of all edges being closed.
Test cases
case 1
in: [4,0.5]
expected: 0.9375
case 2
in: [1,0.3]
expected: 0.30000000000000004
case 3
in: [0,0.5]
expected: 0
case 4
in: [3,1]
expected: 1
Starter codePython
def percolation_open_neighbor_probability(degree, p):
# Your code here
pass4 test cases · run your code against them in the editor