Learn R Programming

ipsRdbs (version 1.0.0)

monty: Simulation of the Monty Hall Problem. This demonstrates that switching is always better than staying with the initial guess. Programme written by Corey Chivers, 2012

Description

Simulation of the Monty Hall Problem. This demonstrates that switching is always better than staying with the initial guess. Programme written by Corey Chivers, 2012

Usage

monty(strat = "stay", N = 1000, print_games = TRUE)

Value

No return value, called for side effects. If the supplied parameter print_games is TRUE, then it prints out the result (Win or Loss) of each of the N simulated games. Finally it reports the overall percentage of winning.

####################################################

Arguments

strat

Strategy to use; possibilities are:

  • "stay": Do not change the initial door chosen.

  • "swap": Swap the door chosen initially.

  • "random": Randomly decide to stay or swap.

N

How many games to play, defaults to 1000.

print_games

Logical; whether to print the results of each game.

Examples

Run this code
# example code
monty("stay")
monty("switch")
monty("random")

Run the code above in your browser using DataLab