Simulation of a Game


Simple Game for any number of players:

Choose any month in a calendar. Every player places a marker on day 1 of the month.

A round consists of each player flipping a coin, and if it lands on heads she advances her marker to the next day. If it lands on tails she moves her marker back one day, unless her marker is on day 1, in which case if stays there. The first player to reach the last day of the month wins.

This game was published several years ago by a fast food chain in a calendar for children. It is easy to imagine that the game might go on for a long time.

The applet below simulates one flip of the coin for one player. The variable p stands for position, and it is initially set equal to 1 for the first day of the month. The variable flip is a simple program that first generates a random number between 0 and 1. If the number is < 0.5, then p is advanced by one. If the number is not less than 0.5, then if p is 1, it stays 1, and if p is larger than 1, then it is decreased by 1.

You simulate a flip of the coin by evaluating the variable flip. To do that, click on flip and type <ctrl> z. The value flip returns is the value of p after the flip. Evaluate flip repeatedly and watch the progress of the player.

The length of an entire game, for one player, can be simulated as in the applet below. The function called game takes one argument, the number of days in the month. Evaluate game by clicking on the formula game(30) to select it, then typing <ctrl> z. Evaluate game several times to see the lengths of several games.