set.seed(19771025)   
N <- 10000  
true_answers <- sample(1:3, N, replace=TRUE)







host_opens <- 2 + (true_answers == 2) 
other_door <- 2 + (true_answers != 2)  


summary( other_door == true_answers )

summary( true_answers == 1)

random_switch <- other_door
random_switch[runif(N) >= .5] <- 1
summary(random_switch == true_answers)








N <- 10000  
true_answers <- sample(1:3, N, replace=TRUE)
user_choice <- sample(1:3, N, replace=TRUE)

host_chooser <- function(user_prize) {
    
    bad_choices <- unique(user_prize)
    
    choices <- c(1:3)[-bad_choices]
    
    if (length(choices) == 1) {  return(choices)}
    else { return(sample(choices,1))}
}

host_choice <- apply( X=cbind(true_answers,user_choice), FUN=host_chooser,MARGIN=1)
not_door <- function(x){ return( (1:3)[-x]) }  
                                                
other_door  <- apply( X = cbind(user_choice,host_choice), FUN=not_door, MARGIN=1)



summary( other_door == true_answers )

summary( true_answers == user_choice)

random_switch <- user_choice
change <- runif(N) >= .5
random_switch[change] <- other_door[change]
summary(random_switch == true_answers)