Introduction to probabability:

Chapter 3 Exercise 11:

A restaurant offers apple and blueberry pies and stocks an equal number of each kind of pie. Each day ten customers request pie. They choose, with equal probabilities, one of the two kinds of pie. How many pieces of each kind of pie should the owner provide so that the probability is about .95 that each customer gets the pie of his or her own choice?

I used the pbinom function to figure out how many pies I need so that 95% of the time, everyone gets their favorite pie.

# Set parameters
n <- 10  # number of customers
p <- 0.5  # probability of choosing either pie
target_probability <- 0.95

# Function to find the minimum number of pies needed
find_min_pies <- function(n, p, target) {
  cumulative_probability <- 0
  for (k in 0:n) {
    # Calculate the binomial probability
    cumulative_probability <- cumulative_probability + dbinom(k, n, p)
    # Check if the cumulative probability meets the target
    if (cumulative_probability >= target) {
      return(k)
    }
  }
  return(n)  # Fallback to the maximum if the target isn't met
}

# Find the minimum number of pies
min_pies <- find_min_pies(n, p, target_probability)

print(paste("Minimum number of pies of each kind needed:", min_pies))
## [1] "Minimum number of pies of each kind needed: 8"

Based on this analysis we found out that we need to have at least 8 pies of each kind. This way, there’s a 95% chance that every customer can choose the pie they want, whether it’s apple or blueberry. I just increased the number of pies step by step, checking the chances each time, until I hit that number where 95% of my customers are happy with their choice.