Skip to content

Instantly share code, notes, and snippets.

@olliefr
Last active May 19, 2016 19:10
Show Gist options
  • Save olliefr/fa1cf400a31dde223628b6891534ddde to your computer and use it in GitHub Desktop.
Save olliefr/fa1cf400a31dde223628b6891534ddde to your computer and use it in GitHub Desktop.
Brain teaser - a simulation approach.
trials <- 1000000
counter <- 0
for (i in 1:trials) {
x <- sample(0:1, size = 400, replace = TRUE)
y <- sum(x)
if (y >= 220) counter = counter + 1
}
print(round(counter / trials, digits=2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment