Created
August 25, 2024 07:49
-
-
Save chenson2018/e4b2690a668ae747712068c20b137891 to your computer and use it in GitHub Desktop.
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
fairness_ratio <- function(coins, flips, trials = 10^6) { | |
all_heads <- rbinom(trials, flips, 1/2) == flips | |
is_unfair <- rbinom(trials, 1, 1 / coins) | |
ratio <- sum(all_heads & !is_unfair) / sum(is_unfair) | |
return(ratio) | |
} | |
# the problem as Daniel stated it | |
fairness_ratio(coins = 10000, flips = 10) | |
# a common variant with roughly equal probability | |
fairness_ratio(coins = 1000, flips = 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment