Exercise 3 chapter 1: In the early 1600s, Galileo was asked to explain the fact that, although the number of triples of integers from 1 to 6 with sum 9 is the same as the number of such triples with sum 10, when three dice are rolled, a 9 seemed to come up less often than a 10|supposedly in the experience of gamblers.
Write a program to simulate the roll of three dice a large number of times and keep track of the proportion of times that the sum is 9 and the proportion of times it is 10.
Can you conclude from your simulations that the gamblers were correct?
Solution:
# number of simulations
n_simulations <- 1000000
# counting for sums of 9 and 10
count_sum_9 <- 0
count_sum_10 <- 0
# the simulation
for (i in 1:n_simulations) {
rolls <- sample(1:6, 3, replace = TRUE)
sum_rolls <- sum(rolls)
if (sum_rolls == 9) {
count_sum_9 <- count_sum_9 + 1
} else if (sum_rolls == 10) {
count_sum_10 <- count_sum_10 + 1
}
}
# proportions
proportion_9 <- count_sum_9 / n_simulations
proportion_10 <- count_sum_10 / n_simulations
cat("Proportion of times sum is 9:", proportion_9, "\n")
## Proportion of times sum is 9: 0.115375
cat("Proportion of times sum is 10:", proportion_10, "\n")
## Proportion of times sum is 10: 0.12452
So the proportions of times the sum was 9 vs. 10 were: 0.115 vs. 0.125. Therefore, the experience of the gamblers was faulty. (it may have been the whiskey on the rocks they liked).