All problems
1D Random Walk Return Probability
Problem
Probability that a symmetric simple random walk on the integers is back at the origin after 2n steps:
P(return) = C(2n, n) / 4^n.
Return 0.0 for negative n.
Hint
The walk must take exactly n steps right and n steps left.
Test cases
case 1
in: [0]
expected: 1
case 2
in: [1]
expected: 0.5
case 3
in: [2]
expected: 0.375
case 4
in: [10]
expected: 0.17619705200195312
Starter codePython
import math
def random_walk_return_probability_1d(n):
# Your code here
pass4 test cases · run your code against them in the editor