Skip to content

Instantly share code, notes, and snippets.

@arademaker
Created March 17, 2012 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arademaker/2065637 to your computer and use it in GitHub Desktop.
Save arademaker/2065637 to your computer and use it in GitHub Desktop.
Monty Hall Problem in R
portas <- function (t){
teste <- 0
amostra <- 0
while (teste < t){
# dist é a distribuição dos conteúdos das portas, 1 marca a porta
# premiada
dist <- c(1,0,0)
dist <- dist[sample(3)]
a <- sample(3,1) # a será a porta que você escolhe
q <- sample(setdiff(1:3,a),1) # q será a porta que o apresentador abre
if (dist[q] != 1){
teste <- teste + 1
if (dist[-c(a,q)] == 1)
amostra <- amostra + 1
}
}
return(amostra/t)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment