```
mHall = function(){
options = c("money", "goat", "goat")
doors = sample(x = options, size = 3)
names(doors) = c("A", "B", "C")
firstChoice = readline(prompt = "Which door do you choose: A, B, or C? ")
if(doors[firstChoice] == "money"){
badDoors = doors[!names(doors) %in% firstChoice]
newOffer = sample(x = badDoors, size = 1)
secondChoice = readline(prompt = paste("I can tell you that door ", names(newOffer),
" has a ",
doors[names(newOffer)],
". Would you like to change your answer (y or n)? ",
sep = ""))
if(secondChoice == "y"){
newChoice = doors[!names(doors) %in% c(firstChoice, names(newOffer))]
return(paste("Here's what's behind door ", names(newChoice), ": ",
newChoice[[1]], sep = ""))
} else {
return(paste("Here's what's behind door ", firstChoice, ": ",
doors[[firstChoice]], sep = ""))
}
} else {
notChosen = doors[!names(doors) %in% firstChoice]
goodDoor = doors[names(which(notChosen == "money"))]
badDoor = doors[names(which(notChosen == "goat"))]
secondChoice = readline(prompt = paste("I can tell you that door ", names(badDoor),
" has a ", doors[names(badDoor)],
". Would you like to change your answer (y or n)? ",
sep = ""))
if(secondChoice == "y"){
newChoice = goodDoor
return(paste("Here's what's behind door ", names(newChoice), ": ",
newChoice[[1]], sep = ""))
} else {
return(paste("Here's what's behind door ", firstChoice, ": ",
doors[[firstChoice]], sep = ""))
}
}
return(doors[firstChoice])
}
```