Algebra tricks in the problem of player gambler's ruin. Let $$S_k=1+(q/p)+\cdots+(q/p)^k =
\begin{cases}
k+1,  & \text{if $p=q$;} \\
\frac{1-(q/p)^{k+1}}{1-(q/p)}, & \text{if $p\neq q$.}
\end{cases}$$
If we substitute $S_k$ in $$v_k=\frac{S_{k-1}}{S_{N-1}}(1/p) \sum_{i=0}^{N-2} S_i -(1/p)\sum_{i=0}^{k-2} S_i$$, then we get 
$$v_k=\begin{cases}
 \\
\frac{1}{q-p} \left(k-N\frac{1-(q/p)^{k}}{1-(q/p)^N}\right), & \text{if $p\neq q$.}
\end{cases}$$
I don't see how to get $v_k$.
Can somebody explain this please?
Note: I think we are just using the $p\neq q$ case in $S_k$ to get $v_k$.
And also, $k=1,2,...,N-1$.
 A: Let $p \neq q$.
We have
$$S_k=\frac{1-\left(\frac{q}{p}\right)^{k+1}}{1-\frac{q}{p}}$$
and
$$v_k=\frac{S_{k-1}}{S_{N-1}}\frac{1}{p} \sum_{i=0}^{N-2} S_i -\frac{1}{p}\sum_{i=0}^{k-2} S_i$$
Substituting, we get:
$$v_k=\frac{1}{p}\left(\left({\frac{1-\left(\frac{q}{p}\right)^{(k-1)+1}}{1-\frac{q}{p}}}\right)\left({\frac{1-\frac{q}{p}}{1-\left(\frac{q}{p}\right)^{(N-1)+1}}}\right)\sum_{i=0}^{N-2} S_i -\sum_{i=0}^{k-2} S_i\right)$$
$$=\frac{1}{p}\left(\left({\frac{1-\left(\frac{q}{p}\right)^{k}}{1-\left(\frac{q}{p}\right)^{N}}}\right)\sum_{i=0}^{N-2} S_i -\sum_{i=0}^{k-2} S_i\right)$$

Now
$$\sum_{i=0}^{K} S_i={\left(\frac{q}{p}\right)}^{K}+2{\left(\frac{q}{p}\right)}^{K-1}+...+n{\left(\frac{q}{p}\right)}^{K+1-n}+...(K+1){\left(\frac{q}{p}\right)}^{0}$$
$$={\left(\frac{q}{p}\right)}^{K}\left(\sum_{i=0}^{K}(i+1){\left(\frac{p}{q}\right)}^{i}\right)$$
Let $x=\frac{p}{q}$.
Then
$$\sum_{i=0}^{K} S_i={x}^{-K}\left(\sum_{i=0}^{K}(i+1){x}^{i}\right)$$
$$={x}^{-K}\left(\sum_{i=0}^{K}\frac{d}{dx}{x}^{i+1}\right)$$
$$={x}^{-K}\left(\frac{d}{dx}\sum_{i=0}^{K}{x}^{i+1}\right)$$
$$={x}^{-K}\left(\frac{d}{dx}\left(x\frac{1-{x}^{K+1}}{1-x}\right)\right)$$
$$=x^{-K}\left(\frac{1-{x}^{K+1}}{1-x}+x\frac{-(K+1){x}^{K}(1-x)+1-{x}^{K+1}}{(1-x)^2}\right)$$
$$=x^{-K}\left(\frac{-(K+1)(1-x){x}^{K+1}+1-{x}^{K+1}}{(1-x)^2}\right)$$
$$=\frac{x^{-K}-(K+2){x}+(K+1){x}^{2}}{(1-x)^2}$$

Substituting in (and still letting $x=\frac{p}{q}$):
$$v_k=\frac{1}{p}\left(\left(\frac{1-x^{-k}}{1-x^{-N}}\right)\left(\frac{x^{-N+2}-Nx+(N-1){x}^{2}}{(1-x)^2}\right)-\left(\frac{x^{-k+2}-kx+(k-1){x}^{2}}{(1-x)^2}\right)\right)$$
$$=\frac{\left({1-x^{-k}}\right)\left({x^{-N+2}-Nx+(N-1){x}^{2}}\right)-(1-x^{-N})\left({x^{-k+2}-kx+(k-1){x}^{2}}\right)}{p(1-x)^2(1-x^{-N})}$$
$$=\frac{(k-N+Nx^{-k}-kx^{-N})x(1-x)}{p(1-x)^2(1-x^{-N})}$$
$$=\frac{x(k(1-x^{-N})-N(1-x^{-k}))}{p(1-x)(1-x^{-N})}$$
$$=\frac{x}{p(1-x)}\left(k-N\frac{1-x^{-k}}{1-x^{-N}}\right)$$
$$=\frac{1}{q-p}\left(k-N\frac{1-\left(\frac{q}{p}\right)^{k}}{1-\left(\frac{q}{p}\right)^{N}}\right)$$
