How to find the expected value of this game? How can I create a function that figures out the expected value for a value that can change.
Example:
I can flip a (fair) coin $n$ number of times.
The pot starts at $\$1$.
If I lose, $50$ cents is added to the pot.
If I win, I take what is in the pot and the pot is reset to $\$1$.
How can I figure out my expected value over $n$ number of coin flips?
The best I have come up with so far is:
$$\sum_{i=0}^n ((\text{currentPot} + (\text{incrmntOnLoss} \cdot \text{ numOfLosses})) \cdot \text{winChance})$$
but this doesn't take into account that the value can reset to $\$1$ after any flip.
It seems to be me that it would be some sort of recursive solution, but I'm unsure how that would be solved in math form
 A: Let $e_{n, p}$ be the expected value over $n$ coin flips if the initial value of the pot is $p$.
$e_{1,p}$ is easy to calculate; $$e_{1,p} = \frac 12 \cdot p = \frac p2$$
Now given the independence of different flips, we can write in general 
$$e_{n,p} = \frac 12(p + e_{n-1, 1}) + \frac 12 e_{n-1, p+1/2}$$
Using this we write out the first few terms:
$$e_{2,p} = \frac 12 \cdot (p + e_{1,1}) + \frac 12 \cdot (e_{1,p+1/2}) = p/2 + 1/4 + p/4 + 1/8 = \frac 34p + \frac 38$$
$$e_{3,p} = \frac 12 (p + e_{2,1}) + \frac 12 e_{2,p + 1/2} = p/2 + 9/16 + 3/8p + 3/16 + 3/16 = \frac 78 p + \frac{15}{16}$$
$$e_{4,p} = \frac 12 (p + e_{3,1}) + \frac 12e_{3,p + 1/2} = p/2 + 7/16  + 15/32 + 7/16p + 7/32 + 15/32 =\frac{15}{16}p + \frac{51}{32}$$
This strongly suggests that the solution is in the form 
$$e_{n,p} = \frac{2^n - 1}{2^n}p + \frac{\alpha_n}{2^{n+1}}$$
Who is $\alpha_n$ though? Since it looks too hard to guess, we just plug it in the general recurrence relation to find that $\alpha_n$ must satisfy 
$$\alpha_n = 2\alpha_{n-1} + 2^n + 2^{n-1} - 3$$
The general solution is $\alpha_n = 2^{n-1}(c + 3n - 6) + 3$ and since $a_2 = 3$ we get $c = 0$. So in the end $\alpha_n = 2^{n-1}(3n - 6) + 3$ and our general solution is in the form 
$$e_{n,p} = \frac{2^{n}-1}{2^n}p + \frac{2^{n-1}(3n - 6) + 3}{2^{n+1}}$$
You are interested in $p=1$, so the solution is 
$$e_{n,1} = \frac{2^{n}-1}{2^n} + \frac{2^{n-1}(3n - 6) + 3}{2^{n+1}}$$
