In: Statistics and Probability
Use R to simulate dealing two cards, and compute these probabilities experimentally.
solution:
ptm <- proc.time()
deck<-rep(c("A", "K", "Q", "J", "10", "9", "8", "7", "6", "5",
"4", "3", "2"), 4)
prob_blk<-c()
prob_19<-c()
for (i in 1:500) {
draw<-matrix(, nrow = 5000, ncol = 2, byrow = T)
countblk=0
count19=0
for(j in 1:5000) {
draw[j,]<-sample(deck, 2)
ifelse((draw[j, 1] == "A" & draw[j, 2] == "10") | (draw[j, 1]
== "10" & draw[j, 2] == "A") | (draw[j, 1] == "A" & draw[j,
2] == "K") | (draw[j, 1] == "K" & draw[j, 2] == "A") | (draw[j,
1] == "A" & draw[j, 2] == "Q") | (draw[j, 1] == "Q" &
draw[j, 2] == "A") | (draw[j, 1] == "A" & draw[j, 2] == "J") |
(draw[j, 1] == "J" & draw[j, 2] == "A"), countblk <-
countblk + 1, ifelse((draw[j, 1] == "A" & draw[j,2] == "8") |
(draw[j, 1] == "8" & draw[j, 2] == "A") | (draw[j, 1] == "9"
& draw[j, 2] == "10") | (draw[j, 1] == "10" & draw[j, 2] ==
"9") | (draw[j, 1] == "9" & draw[j, 2] == "K") | (draw[j, 1] ==
"K" & draw[j, 2] == "9") | (draw[j, 1] == "9" & draw[j,2]
== "Q") | (draw[j, 1] == "Q" & draw[j, 2] == "9") | (draw[j, 1]
== "9" & draw[j, 2] == "J") | (draw[j, 1] == "J" & draw[j,
2] == "9"), count19 <- count19 + 1, count19))
}
prob_blk[i] = countblk/5000
prob_19[i] = count19/5000
}
mean(prob_blk)
mean(prob_19)
proc.time() - ptm
please give me thumb up