You and a friend play the following game: You pay your friend $3 each turn and then flip a fair coin. It it’s tails, your friend pays you $(2^n), where n is the number of times you’ve flipped the coin, and the game ends. If it’s heads, you have the choice of stopping and continuing. If you have m dollars to start with, and you play the game either until you win or until you have no money left, what will you win on the average?

Ah the good old St Petersburg Paradox.

Well, if you and your friend each have a infinite amount of money, then you can expect to win and infinite amount, on average.

Google St Petersburg Paradox for more info.

To calculate the average amount you will win in this game, we need to consider the probabilities of various outcomes occurring and their respective payoffs. Let's analyze the game step by step.

1. The first turn:
- You pay your friend $3. So, you will have m-3 dollars left.
- The coin is flipped. Let's consider two cases:
a. If it's tails (with a probability of 0.5): Your friend will pay you $(2^0) = $1, and the game ends.
b. If it's heads (with a probability of 0.5): You have the choice to stop or continue.

2. Continuation after a heads flip:
- If you decide to continue, the game repeats with the same rules as in the first turn but starting with m-6 dollars instead of m dollars. The probabilities and payoffs for the subsequent turns will be the same as in the first turn.

Now, let's calculate the expected value (average amount you will win) step by step using the concept of expectation:

1. Probability of winning $1 on the first turn: 0.5
2. Probability of getting heads on the first turn and continuing: 0.5 * expectation of winning from the next turn.
3. Expected value after the first turn:
- If tails on the first turn, you win $1 with a probability of 0.5.
- If heads on the first turn, you continue with a probability of 0.5, and the expected value from the next turn will be the same.
So, the expected value after the first turn = probability of tails on the first turn * $1 + probability of heads on the first turn * (0.5 * expected value from the next turn).

Using this recursive calculation, you can find the expected value after each turn until you either win a game (by getting tails) or lose (by running out of money). The final expected value will be the sum of expected values after each turn.

Please note that calculating the exact expected value in this game involves an infinite series summation, making it a bit complicated. You can use mathematical software or tools to evaluate the series and find a numerical approximation.