simulate_flips <- function(choice_flips, n_trials, pct_heads, win_prop) {
### You pick choice_flips, for n_trials, with fair coin = 50 pct_heads,
### and you have to beat win_prop proportion of flips being heads
# set seed
set.seed(606)
# simulate the success of your choice
wins <- 0
# simulate n_trials for each choice
for (i in 1:n_trials) {
# run the trial n_trial times
results <- sample(c(rep('heads', pct_heads), rep('tails', 100 - pct_heads)),
choice_flips, replace = TRUE)
if (sum(results == 'heads') / choice_flips > win_prop &
sum(results == 'tails') / choice_flips > win_prop) { wins <- wins + 1}
}
glue("With {choice_flips} flips per round: {wins} wins out of {n_trials} rounds")
}
simulate_flips(10, 1e4, 50, .40)
## With 10 flips per round: 2461 wins out of 10000 rounds
simulate_flips(100, 1e4, 50, .40)
## With 100 flips per round: 9420 wins out of 10000 rounds