Skip to content

Instantly share code, notes, and snippets.

@joowkim
Last active October 11, 2022 13:33
Show Gist options
  • Save joowkim/2a4a9598898eedcb8a6ebc092253ec23 to your computer and use it in GitHub Desktop.
Save joowkim/2a4a9598898eedcb8a6ebc092253ec23 to your computer and use it in GitHub Desktop.
coin-test problem
func <- function(num) {
result <- c()
vec <- c("TT", "TT", "HT", "TH", "HH", "HH")
# bst <- sample(vec, num, replace = T)
for (i in 1:num) {
coin <- sample(vec, 1)[1]
if (startsWith(coin, "H")) {
result <- c(result, coin)
} else {
next
}
}
return (result)
}
a <- func(50000)
table(a)[1] / (table(a)[1] + table(a)[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment