Here's how to play jeu-vain, a gambling game that I just invented:
The player puts up one dollar and receives a standard six-sided die, which he then rolls several times. After each roll, a casino employee announces the running total of the numbers that have come up. The player continues to roll until the total is greater than or equal to 15. If the last total is exactly 15, he wins; he gets his dollar back, and the casino gives him two dollars more. If the total goes over 15, however, the player is ``busted'' and the casino keeps his dollar. In either case, the casino takes back the die; if the player wants to play another round, he has to put up a dollar again.
A sample round: The player puts down a dollar, receives the die, and rolls a two (``Two!'' calls the casino employee), then a one (``Three!''), another one (``Four!''), another two (``Six!''), a three (``Nine!''), another two (``Eleven!''), another three (``Fourteen!''), and finally another one (``Fifteen and out!''). The casino employee returns the player's dollar and adds two more.
Another sample round: The player puts down a dollar, receives the die, and rolls a two (``Two!''), a five (``Seven!''), a three (``Ten!''), and a six (``Sixteen and you're over.''). The casino employee rakes in the player's dollar.
Write a Scheme procedure jeu-vain that takes two arguments, an initial bankroll (in dollars) and a maximum number of rounds to be played, and simulates the activity of a gambler who plays round after round of the game until either the maximum number of rounds has been reached or her bankroll is exhausted. The procedure should return the number of dollars remaining in the player's bankroll when play is halted. Demonstrate your procedure by simulating a player who starts with a bankroll of $50 and plays two hundred rounds of the game.
The jeu-vain procedure can (and should) call other procedures that you also define. It would be a good idea, for instance, to define a separate procedure that simulates a single round of the game, returning #t if the player wins and #f if she loses.
Write a Scheme procedure that computes the exact probability that the player will win one round of jeu-vain. (Hint: Use a kernel procedure that takes the current value of the running total as an argument. If the running total exceeds 15, the player's chance of winning is 0; if it equals 15, it is 1; in any other case, it is one-sixth of the sum of her chances of winning after rolling a 1, her chances of winning after rolling a 2, ..., and her chances of winning after rolling a 6. Since each of these alternatives produces a new running total, you can take advantage of recursion to compute these subsequent probabilities.)
The player's mathematical expectation is the result of subtracting the product of the amount he might lose and the probability that he will lose it from the product of the amount he might win and the probability that he will win it. Using the answer you obtained in part B, use Scheme to compute the jeu-vain player's single-round mathematical expectation, in dollars.
This document is available on the World Wide Web as
http://www.math.grin.edu/courses/Scheme/spring-1998/exercise-3.html
created February 12, 1998
last revised June 21, 1998