Skip to content

Instantly share code, notes, and snippets.

@diamonaj
Created September 26, 2022 18:15
Show Gist options
  • Select an option

  • Save diamonaj/e75cc606f1a0869d035c696b4fb9fcc4 to your computer and use it in GitHub Desktop.

Select an option

Save diamonaj/e75cc606f1a0869d035c696b4fb9fcc4 to your computer and use it in GitHub Desktop.
die_rolls <- 1:6
storage <- c()
for(i in 1:1000)
{
rolls_for_the_week <- sample(die_rolls, 7, replace = TRUE)
storage[i] <- sum(rolls_for_the_week == 1) == 0 # if there's no 1, then TRUE
}
cat("\nthe probability of not rolling a 1 all week is estimated =",
sum(storage)/1000, "\n")
cat("\nthe probability of rolling at least a single 1 all week is estimated =",
1 - sum(storage)/1000, "\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment