Last active
September 2, 2024 03:58
-
-
Save alejandrohagan/d0d9f7771a07be12107f224281052048 to your computer and use it in GitHub Desktop.
Churn 2024-09-01
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
#You have 3 urns, each containing 100 balls. | |
#In the first two, 99 of the balls are red and the last is green. | |
#In the third urn, all 100 balls are red. | |
#You choose one of the urns at random and remove 99 randomly chosen balls from it; they’re all red. | |
#The last is probably? | |
library(tidyverse) | |
pick_ball <- function(){ | |
churn1 <- c(rep(1,99),0) | |
churn2 <- c(rep(1,99),0) | |
churn3 <- rep(1,100) | |
churn <- sample( | |
list(churn1=churn1,churn2=churn2,churn3=churn3) | |
,1 | |
) |> | |
pluck(1) | |
picks <- sample(churn,100,replace = FALSE) | |
if(all(picks[1:99]==1)){ | |
out <- picks[100] | |
return(out) | |
} | |
} | |
out <- replicate(1000000,pick_ball()) |> | |
purrr::flatten_dbl() | |
out |> mean() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment