Gambler's ruin probability

Write codeHard30 minCitadel style

Your task

In the gambler's ruin problem you start with i dollars and bet $1 per round; you win a round (gain 1) with probability p = p_num/p_den, else lose 1. You stop at $0 (ruin) or at $N (target). Return the probability of reaching $N before $0, rounded to 6 decimals. Handle both the fair (p=1/2) and biased cases.

Examples

gamblers_ruin_prob(N: int, i: int, p_num: int, p_den: int) -> float
Example 1
Inputgamblers_ruin_prob(10, 5, 1, 2)
Output0.5