Skip to content

Instantly share code, notes, and snippets.

@carlislerainey
Created December 2, 2025 13:25
Show Gist options
  • Select an option

  • Save carlislerainey/20b49faaf105db2211b72765c74d14b7 to your computer and use it in GitHub Desktop.

Select an option

Save carlislerainey/20b49faaf105db2211b72765c74d14b7 to your computer and use it in GitHub Desktop.
Tasting Tea Simulation
# ---- set up experiment
cups <- c(
rep("Milk First", 4),
rep("Tea First", 4)
)
cups
randomization <- sample(cups)
# ---- where are the milk-first cups?
# actually
truth <- which(randomization == "Milk First")
truth
# guesses
guesses <- sample(1:8, 4)
guesses
# ---- how many guesses are correct
correct <- intersect(truth, guesses)
correct
length(correct)
# ---- now do this many times and track number correct
n_iter <- 10000
n_correct <- numeric(n_iter)
for (i in 1:n_iter) {
# randomize and guess
randomization <- sample(cups)
truth <- which(randomization == "Milk First")
guesses <- sample(1:8, 4)
correct <- intersect(truth, guesses)
# track number of correct guesses
n_correct[i] <- length(correct)
}
table(n_correct) # raw counts
prop.table(table(n_correct)) # convert to proportions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment