Question

A die is rolled three times. Find the probability that the sum of the outcomes is:

  1. greater than 9.
  2. an odd number.

Christian’s Response:

Part A:

In the code below, I simulated a trail where a die is rolled three times. I chose 10,000 as the number of trails since a large trail will lead to more accuracy.

# set the number of trials
trials <- 10000

# simulate outcome rolling die 3 times
die_outcome <- matrix(sample(1:6, trials * 3, replace = TRUE), ncol = 3)

# gets sum of each outcome
sums <- apply(die_outcome, 1, sum)

# probability of getting sum greater than 9
greater_than_9 <- mean(sums > 9)

cat("The probability of getting a sum greater than 9 is", greater_than_9)
## The probability of getting a sum greater than 9 is 0.6202

Part B:

Christian’s Response:

The code below search searches for sums that deliver an odd number as a result.

odd <- mean(sums %% 2 == 1)
cat("The probability of getting an odd number is",odd)
## The probability of getting an odd number is 0.4991