Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Alice wants to join her school's Probability Student Club. Membership dues are computed via one of two simple probabilistic games.
- //The first game: roll a die repeatedly. Stop rolling once you get a five followed by a six.Your number of rolls is the amount you pay, in dollars.
- //The second game: same, except that the stopping condition is a five followed by a five.
- //Which of the two games should Alice elect to play? Does it even matter? Write a program to simulate the two games and calculate their expected value.
- Random rand = new Random();
- //variables
- int previous = -1;
- int current;
- int counter = 0;
- bool condition = false;
- //five followed by six
- while (condition == false)
- {
- current = rand.Next(1, 7);
- counter++;
- if (previous == 5 && current == 6) { condition = true; Console.WriteLine("five followed by six cost=" + counter); }
- else { previous = current; }
- }
- //resetting variables
- previous = 0;
- current = 0;
- counter = 0;
- condition = false;
- //five followed by five
- while (condition == false)
- {
- current = rand.Next(1, 7);
- counter++;
- if (previous == 5 && current == 5) { condition = true; Console.WriteLine("five followed by five cost=" + counter); }
- else { previous = current; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement