As the title says, I'm trying to find the formula that calculates the average cost for a game of chance.
Here are the rules of the game -
- There is a 25% chance to win a game
- The player wants to win exactly 3 games in one day. After that he stops playing.
- There is a maximum of 10 games per day
- The player pays for each game. The cost is 5 coins per game
What is the average total amount of money the player would have to spend until he reaches a day in which he has won exactly 3 games?
At first, I thought I could use the binomial distribution formula to solve the chance of getting exactly 3 wins in a day and use the result to calculate the average cost.
$$E(X) = \binom{10}{3}0.25^{3}(0.75)^{7}$$
The result is ~ 0.2502, which means meeting our goal of exactly 3 wins approximately once every 4 games. That didn't seem right. Because the binomial distribution doesn't take into account the fact that the player stops playing after 3 wins. It assumes the player always plays 10 games every day.
Since this didn't seem like the correct answer I wrote a little python program to approximate the true answer.
The program simulates 10 million iterations with the rules above (the player has a maximum of 10 games per day, or 3 wins, whichever comes first. A game cost 5 coins and there's a 25% chance to win a game).
These were the results -
- The player will have to play an average of 18.329 games until the goal of a day with exactly 3 wins is met
- Times that by the cost of 5 coins per game gives us an average cost of 91.64 coins
The full output of the program can be seen here.
So, is there a way to get to this answer without iterating through 10 million cases? Is there a formula to calculate this?
Let's consider a single day. The probability that the third win occurs on game $n$ is $$p_n=\binom {n-1}2\times .25^3\times .75^{n-3}$$
Thus the probability that you achieve success on a single day is $$\alpha=\sum_{n=3}^{10} p_n=.4744$$
and the expected number of games it will take you conditioned on knowing that this is a winning day is $$\sum_{n=3}^{10}n\times p_n \times \frac 1{.4744}= 7.25188$$
It follows that the answer to your question is $$7.25188+10\times \sum_{k=1}^{\infty} (k-1)\times (1-.4744)^{k-1}\times .4744=\boxed {18.3308}$$
Which I think confirms your simulation nicely.
Variant (for the last step): Letting $E$ be the desired expectation, we consider the first day. Either you succeed on that day, in which case you expect to play $7.25188$ games, or you fail and the game restarts (only now you have played $10$ games). Thus $$E=(1-\alpha)(E+10)+\alpha\times 7.25188$$
which is easily solved to yield the same result as before.