Last active
May 19, 2016 19:10
-
-
Save olliefr/fa1cf400a31dde223628b6891534ddde to your computer and use it in GitHub Desktop.
Brain teaser - a simulation approach.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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