|
This month's Challenge Question: Specs & Techs from IHS Engineering360:
Try this
game: you flip a coin until you get a head and you win one dollar every time
you flip the coin. For example if you get a heads the first time, you get one
dollar; if you get a tails the first time and a head the second time, you get
two dollars; and so on. What is the maximum expected dollars you can make every
time you play this game?
And the answer is:
Every time
you flip the coin the probability of getting heads is ½, so the probability of
winning just one dollar is ½; the probability of winning two dollar is 2/4 (=
½) and so forth. Then, the expected winning is given by this series:

This is a
convergent series so its sum is a finite number. You can find the value of this
series using normal mathematical techniques, or you can use the following C++
program to find that the series converges to 2.0. So you will win no more
than $2.00 each time you play the game.
// Solution to Challenge Question for August 2015
#include <iostream>
#include <math.h>
using namespace std;
const int MAX = 100;
int main ( ) {
int
n; // n is the number of coins you end
up flipping
double
expectedValue = 0.0;
for
(int i=1; i <= MAX; i++) expectedValue += i/pow (2,i);
cout
<< "\nExpected Average Value = " << expectedValue;
return
0;
}
|
Good Answers:
"Almost" Good Answers: