Suppose that in game of chance, you bet an initial amount of money, and every ti
ID: 3828205 • Letter: S
Question
Suppose that in game of chance, you bet an initial amount of money, and every time you play, the money is doubled with probability p and halved with probability 1 p. (a) What value of p gives you an expected value of your money equal to its value before the play? [10 points] (b) With this value of p, start the game with $100 and play the game for 5 plays by (using a random number generator app), listing the value of your money after each play. Do three more 5-play games each starting with $100 and list the value after each play for each game. (c) Do the results of the game playing match with the fact that the expected value of the money is unchanged after each play, and if not, what ideas do you have to explain the discrepancy?
Explanation / Answer
#include #include #include #include #include #include using namespace std; #define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0])) int checkDistribution(double random, const map &distribution_map) { int index = 0; map::const_iterator it = distribution_map.begin(); for (; it!=distribution_map.end(); ++it) { if (random < (*it).first) { int randomInternal = 0; if ((*it).second.size() > 1) randomInternal = rand() % ((*it).second.size()); index = (*it).second.at(randomInternal); break; } } return index; } void nextNum(int* results, const map &distribution_map) { double random = (double) rand()/RAND_MAX; int index = checkDistribution(random,distribution_map); results[index]+=1; } int main() { srand (time(NULL)); int results [] = {0,0,0,0,0}; int numbers [] = {-1,0,1,2,3}; double prob [] = {0.01, 0.3, 0.58, 0.1, 0.01}; int size = ARRAY_SIZE(numbers); // Building Distribution map distribution_map; map::iterator it; for (int i = 0; i second.push_back(i); else { vector vec; vec.push_back(i); distribution_map[prob[i]] = vec; } } // PDF to CDF transform map cumulative_distribution_map; map::iterator iter_cumulative; double cumulative_distribution = 0.0; for (it=distribution_map.begin();it!=distribution_map.end();++it) { cumulative_distribution += ((*it).second.size() * (*it).first); cumulative_distribution_map[cumulative_distribution] = (*it).second; } for (int i = 0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.