ComeçarComece de graça

Simulate 10000 games

Now, let's simulate 10000 games and answer the following: since 2 and 12 are equally unlikely, how often does either a 2 or a 12 get rolled more than twice within a game?

Basic strategy indicates that the spaces with 2 or 12 should be avoided because they are the least probable, and although this is true theoretically, here we will investigate how surprising it really should be if they end up coming up more frequently than expected. The roll_dice function from previous exercises has been preloaded for you.

Este exercício faz parte do curso

Probability Puzzles in R

Ver curso

Instruções do exercício

  • Use the replicate function to roll two dice 60 times.
  • Use a compound condition to check whether either a 2 or 12 was rolled more than twice.
  • Print your estimated probability of rolling a 2 or 12 more than twice within a game.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

set.seed(1)
counter <- 0

for(i in 1:10000){
  # Roll two dice 60 times
  rolls <- ___
  
  # Check whether 2 or 12 was rolled more than twice
  if(___){
    counter <- counter + 1
  }  
}

# Print the answer
print(___)
Editar e executar o código