**updated more than 1 year ago**, some information may be outdated!

Consider a gambler who starts with an initial fortune of $i$$ and then on each successive gamble either wins $1$$ or loses $1$$ independent of the past with probabilities $p$ and $q = 1-p$ respectively. The gambler's objective is to reach a total fortune of $N$$, without first getting ruined (running out of money).

Let $P_i$ be the probability that the gambler wins when starting with $i$$, we have

Finally,

Note that, $1-P_i$ is the probability of ruin.

**Another type of this question**: Consider an ant walking along the positive integers. At position $i$, the ant moves to $i+1$ with probabilities $p$ and to $i-1$ with probabilities $q$. If the ant reach $0$, it stops walking. Starting from $i>0$, what is the probability that the ant reaches $i=N$ before reaching $0$?

Sometimes, we consider above problem as a random walk problem. This post is copied from this and we have a backup version here.