Skip to content

Instantly share code, notes, and snippets.

@joowkim
Last active December 9, 2020 01:28
Show Gist options
  • Save joowkim/dced1a6da642cf11f4f1cba52945754a to your computer and use it in GitHub Desktop.
Save joowkim/dced1a6da642cf11f4f1cba52945754a to your computer and use it in GitHub Desktop.
birth <- function(n) {
deno <- 365^n
nume <- prod(365:(365-n+1))
result <- 1- (nume / deno)
return(result)
}
nrep <- 10000
cnt <- 0
for (i in 1:nrep) {
x <- sum(duplicated(sample(1:365,23,replace = TRUE)))
if (x !=0) {
cnt = cnt+1
}
}
print(cnt/nrep)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment