In a 5-card hand – Counting

We evaluated three card probabilities in the previous post. It is important to verify the calculations, well, by actually counting the occurrences by shuffling it a million times and drawing five cards. But first, build the deck:

suits <- c("Diamonds", "Spades", "Hearts", "Clubs")
face <- c("Jack", "Queen", "King")
numb <- c("Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten")
face_card <- expand.grid(Face = face, Suit = suits)
face_card <- paste(face_card$Face, face_card$Suit)

numb_card <- expand.grid(Numb = numb, Suit = suits)
numb_card <- paste(numb_card$Numb, numb_card$Suit)

Aces <- paste("Ace", suits) 

deck <- c(Aces, numb_card, face_card)

Four face cards

itr <- 1000000

shuff <- replicate(itr, {
draw <- sample(deck, 5, replace = FALSE, prob = rep(1/52, 52))  

dr <- sum(str_detect(draw, "Queen|King|Jack"))

if(dr == 4){
  counter <- 1
}else{ counter <- 0}

})

mean(shuff)

The answer turns out to be: 0.007548

Three cards are kings

itr <- 1000000

shuff <- replicate(itr, {
draw <- sample(deck, 5, replace = FALSE, prob = rep(1/52, 52))  

dr <- sum(str_detect(draw, "King"))

if(dr == 3 ){
  counter <- 1
}else{ counter <- 0}

})

mean(shuff)
0.001717

All five cards are hearts

itr <- 1000000

shuff <- replicate(itr, {
draw <- sample(deck, 5, replace = FALSE, prob = rep(1/52, 52))  

dr <- sum(str_detect(draw, "Hearts"))

if(dr == 5 ){
  counter <- 1
}else{ counter <- 0}

})

mean(shuff)
0.00048