### Monty Hall problem simulation with N number of doors, where N > 2.

This is one possible generalization of the famous Monty Hall problem, a game situation with 3 doors,
and a grand prize hidden behind one door. You make a door choice initially, then the game
host, Monty Hall, opens another door (one of the two remaining doors), only to reveal a booby prize.

You then get to decide if you want to stay by your first choice, or change. In this case, a change
means to switch your choice to the door not opened by Monty.

In this generalization there is a total N doors, let's say 4. Monty will still open only one door after your
selection, and he'll always reveal a booby prize.
You then have to decide beetween 3 strategies: either you can

A) stay by your initial door selection,

B) make another choice among all doors except the opened one,

C) make another choice among all doors except the opened one and except your initial selection.

Many people seem to reason that it cannot matter, so you can just stay by your first choice.
However, for the 3-door game, the 3 strategies above will prove to have winning probabilities of
1/3, 1/2 and 2/3, respectively. So there is a doubling in probability from A) to C). But, more importantly,
a 33.3% relative gain in going for strategy C) instead of B).

The goal here is to empirically show that it always pays off to make a new door choice excluding the
initial selection
- i.e. strategy C) above - regardless of N, even though the relative gain in winning
probability will soon get small with increasing N.

This result can be proven theoretically by applying Bayes theorem, which I'll refrain from here.

Here's some R simulation code.

```_____________________________________________________________________

MH_sim <- function(doors=4, sim.trials=20000) {

# number of doors (default 4)
# number of simulation trials (default 20000)

if (doors<3) stop("this game needs 3 or more doors")

chooser <- function(x) { i <- (1:doors)[-x]; if (length(i)>1) sample(i,1) else i }

p100 <- function(...) { cat("\nMonty Hall game for", doors, "doors",
if (doors>3) "(i.e. more than 3)", "   ( #sim.trials =", sim.trials, ")",
"\nSimulation of % winning probability by first and second choices, like this:\n",
"After Monty reveals one door, a new choice is made either among all closed\n",
"doors or the closed doors excluding the first selected door",
if (doors==3) "(here only one)", "\n");
print(c(...) * 100, digits=3) }

prize_door <- sample(1:doors, sim.trials, replace=TRUE)
first_choice <- sample(1:doors, sim.trials, replace=TRUE)

host_opens <- apply(cbind(prize_door, first_choice), 1, chooser)

new_choice_all <- apply(cbind(host_opens), 1, chooser)
new_choice_ex_1st <- apply(cbind(host_opens, first_choice), 1, chooser)

p100("By 1st choice standing" = (Pr.1st_win <- mean(first_choice == prize_door)),
"New choice all doors" = (Pr.2nd_all_win <- mean(new_choice_all == prize_door)),
"New choice ex 1st" = (Pr.2nd_ex_1st_win <- mean(new_choice_ex_1st == prize_door)),
"Exclusion gain" = Pr.2nd_ex_1st_win / Pr.2nd_all_win - 1 )
}
_____________________________________________________________________

# Sample run:
> MH_sim()

Monty Hall game for 4 doors (i.e. more than 3)    ( #sim.trials = 20000 )
Simulation of % winning probability by first and second choices, like this:
After Monty reveals one door, a new choice is made either among all closed
doors or the closed doors excluding the first selected door
By 1st choice standing   New choice all doors      New choice ex 1st         Exclusion gain
24.8                   33.4                   37.6                   12.6
>
```