All problems
Arcsine Law Last Visit Probability
Problem
Arcsine law for a symmetric simple random walk. Return the probability that the last visit to 0 up to time 2n occurs at time 2k:
P = C(2k, k) * C(2n - 2k, n - k) / 4^n.
Return 0.0 when k lies outside 0..n.
Hint
The last visit splits the walk into two independent excursions.
Test cases
case 1
in: [1,0]
expected: 0.5
case 2
in: [1,1]
expected: 0.5
case 3
in: [2,0]
expected: 0.375
case 4
in: [2,1]
expected: 0.25
case 5
in: [2,2]
expected: 0.375
Starter codePython
import math
def arcsine_last_visit_probability(n, k):
# Your code here
pass5 test cases · run your code against them in the editor