1 Problem


A bag contains 40 skittles: 16 yellow, 14 red, and 10 orange. You draw 3 skittles at random (without replacement) from the bag. What is the probability that you get 2 skittles of one color and another skittle of a different color?

1.1 Data


# A bag contains 40 skittles: 16 yellow, 14 red, and 10 orange.
skittles <- c(rep("Yellow", 16), rep("Red", 14), rep("Orange", 10))

# Skittles amount
length(skittles) 
## [1] 40
skittles
##  [1] "Yellow" "Yellow" "Yellow" "Yellow" "Yellow" "Yellow" "Yellow" "Yellow"
##  [9] "Yellow" "Yellow" "Yellow" "Yellow" "Yellow" "Yellow" "Yellow" "Yellow"
## [17] "Red"    "Red"    "Red"    "Red"    "Red"    "Red"    "Red"    "Red"   
## [25] "Red"    "Red"    "Red"    "Red"    "Red"    "Red"    "Orange" "Orange"
## [33] "Orange" "Orange" "Orange" "Orange" "Orange" "Orange" "Orange" "Orange"

1.2 Example Result


Single experiment of draw 3 skittles at random (without replacement) from the bag:

set.seed(20211222) # For reproducibility
draw_one <- sample(x = skittles, 
                   size = 3, 
                   replace = FALSE)

draw_one
## [1] "Red"    "Yellow" "Yellow"

Possible outputs from each experiment:

  1. Three skittles of same color: Red - Red - Red
  2. Two skittles of one color and another skittle of a different color: Red - Yellow - Yellow
  3. The three skittles show different color: Red - Yellow - Orange

2 Solution


Two approaches:

  • Monte Carlo Simulation
  • Probability and Counting Theory

2.1 Monte Carlo Simulation


Repeat the experiment a large enough number of times, equivalent to doing it over and over. Stochastic process.

# 1. Experiment
draw_one
## [1] "Red"    "Yellow" "Yellow"
# 2. Duplicate elements
duplicated(draw_one)
## [1] FALSE FALSE  TRUE
# 3. If the sum of logical duplicate elements is 1, then there are two skittles of one color and another skittle of a different color
sum(duplicated(draw_one))
## [1] 1

Using the replicate function to repeat the experiment a million times:

library(dplyr)  # if_else function

results <- replicate(n = 1000000, {
  # 1. draw 3 skittles at random
  draws <- sample(x = skittles, 
                  size = 3, 
                  replace = FALSE)
  # 2. 
  sum <- sum(duplicated(draws))
  # 3. If the sum is different to 1 then takes a value zero
  experiment <- if_else(sum == 1, 1, 0)
})

The mean of the output vector results is the probability of getting 2 skittles of one color and another skittle of a different color:

mean(results)
## [1] 0.668082

The probability that you get 2 skittles of one color and another skittle of a different color from a bag that contains 40 skittles: 16 yellow, 14 red, and 10 orange is 0.668 or 66.8%

2.2 Probability and Counting Theory


There are three ways to select two colors (a, b) given the condition one is repeated:

  • (a, a, b)
  • (a, b, a)
  • (b, a, a)
# Two yellow skittles and another of different color
((16/40)*(15/39)*(24/38))*3 + 
# Two red skittles and another of different color
((14/40)*(13/39)*(26/38))*3 + 
# Two orange  skittles and another of different color
((10/40)*(9/39)*(30/38))*3 
## [1] 0.6676113