A coin is under a cup. One person is blindfolded and another shuffles the cups. The blindfolded person is asked to choose and cup without the coin is shown (not one they chose). They are then asked to switch. In the simulation the person would always switch and their win/loss ratio would be recorded.
doors = c("A", "B", "C")
xdata = c()
for (i in 1:10000)
{
prize = sample(doors)[1]
pick = sample(doors)[1]
open = sample(doors[which(doors != pick & doors != prize)])[1]
switchyes = doors[which(doors != pick & doors != open)]
if(pick == prize){xdata = c(xdata, "noswitchwin")}
if (switchyes == prize){xdata = c(xdata, "switchwin")}
}
xdata[1:10]
## [1] "switchwin" "switchwin" "switchwin" "switchwin" "switchwin"
## [6] "noswitchwin" "noswitchwin" "noswitchwin" "switchwin" "switchwin"
length(which(xdata == "switchwin"))
## [1] 6707
length(which(xdata == "noswitchwin"))
## [1] 3293