Page 289 Exercise 1
A die is rolled three times. Find the probability that the sum of the outcomes is (a) greater than 9. (b) an odd number
# (A) Greater than 9
# Let's set the probability values for the sum of two die thrown as we have found above.
P_S2_2 <- 1/36
P_S2_3 <- 2/36
P_S2_4 <- 3/36
P_S2_5 <- 4/36
P_S2_6 <- 5/36
P_S2_7 <- 6/36
P_S2_8 <- 5/36
#P_X3 for any value X where X is from 1 to 6, its probability will always be 1/6, no matter what the value is
P_X3_1 <- 1/6
P_X3_2 <- 1/6
P_X3_3 <- 1/6
P_X3_4 <- 1/6
P_X3_5 <- 1/6
P_X3_6 <- 1/6
# Let's calculate the probabilities for the sum of 3 dies up to a total sum of 9
P_S3_3 <- P_S2_2 * P_X3_1
P_S3_4 <- P_S2_2 * P_X3_2 + P_S2_3 * P_X3_1
P_S3_5 <- P_S2_2 * P_X3_3 + P_S2_3 * P_X3_2 + P_S2_4 * P_X3_1
P_S3_6 <- P_S2_2 * P_X3_4 + P_S2_3 * P_X3_3 + P_S2_4 * P_X3_2 + P_S2_5 * P_X3_1
P_S3_7 <- P_S2_2 * P_X3_5 + P_S2_3 * P_X3_4 + P_S2_4 * P_X3_3 + P_S2_5 * P_X3_2 + P_S2_6 * P_X3_1
P_S3_8 <- P_S2_2 * P_X3_6 + P_S2_3 * P_X3_5 + P_S2_4 * P_X3_4 + P_S2_5 * P_X3_3 + P_S2_6 * P_X3_2 + P_S2_7 * P_X3_1
P_S3_9 <- P_S2_3 * P_X3_6 + P_S2_4 * P_X3_5 + P_S2_5 * P_X3_4 + P_S2_6 * P_X3_3 + P_S2_7 * P_X3_2 + P_S2_8 * P_X3_1
# Sum of all the P Values from X=3 to X = 9
P_sum_3_9 <- P_S3_3 + P_S3_4 + P_S3_5 + P_S3_6 + P_S3_7 + P_S3_8 + P_S3_9
# However, we need to solve for the probability that the sum will be greater than 9
print(paste0("The probability of the sum of 3 die will be greater than 9 will be: ", 1 - P_sum_3_9))
## [1] "The probability of the sum of 3 die will be greater than 9 will be: 0.625"
# (B) An odd number
range_sum <- 3:18
# How many of them are odd?
odd <- 0
for (i in range_sum){
if (i %% 2 == 0){
odd <- odd + 1
}
}
# How many of them are even?
even <- 0
for (i in range_sum){
if (i %% 2 == 1){
even <- even + 1
}
}
# What is the probability that the sum of 3 die is odd?
print(paste0("Probability that the sum of 3 die is odd: ", odd/length(range_sum)))
## [1] "Probability that the sum of 3 die is odd: 0.5"
As per prof. shorter version:
tmp=sample(seq(1:6),1000000,replace=T)+sample(seq(1:6),1000000,replace=T)+sample(seq(1:6),1000000,replace=T)
print(c(length(tmp[tmp>9])/length(tmp),length(tmp[tmp%%2==1])/length(tmp)))
## [1] 0.624882 0.499972