Coding challenge

Suppose you're on a game show with 3 doors. Behind one door is a car; behind the other two are goats. You pick a door (say Door 1). The host, Monty Hall, who knows what is behind the doors, opens one of the other doors (say Door 3), revealing a goat. He then asks: "Do you want to switch to Door 2?"

Write a Monte Carlo simulation of $10{,}000$ games. If you always decide to switch doors, what percentage of games do you win? Can you explain why switching doubles your chances of winning from $1/3$ to $2/3$?

Type your code here:


Lua reference

See your results here: