LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Probability Puzzles in R

Kurs anzeigen

Anleitung zur Übung

  • 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.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

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(___)
Code bearbeiten und ausführen