Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-099

Ehrenfest Chain Step

Problem

The Ehrenfest urn has d balls split between two boxes. From state k (balls in the left box) one random ball is moved each step, so:

P(k -> k - 1) = k / d and P(k -> k + 1) = (d - k) / d.

Return the two transition probabilities as [down, up]. Return [0.0, 0.0] for invalid inputs.

Hint

Exactly one of the d balls switches boxes each step.

Test cases

case 1
in: [4,0]
expected: [0,1]
case 2
in: [4,2]
expected: [0.5,0.5]
case 3
in: [4,4]
expected: [1,0]
case 4
in: [0,0]
expected: [0,0]
Starter codePython
def ehrenfest_step(d, k):
    # Your code here
    pass

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