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?
dice.sim<- function(n.dice){
dice <- sample(x = 1:6, size = n.dice, replace = TRUE)
return(sum(dice))
}
Set1<- data.frame(replicate(500, dice.sim(3)))
Set1_9s <- Set1%>%
rename(sim1 = 1)%>%
filter(sim1 == 9)
count1_9 <- count(Set1_9s)
Set1_10s <- Set1%>%
rename(sim1 = 1)%>%
filter(sim1 == 10)
count1_10 <- count(Set1_10s)
### Set 2
Set2<- data.frame(replicate(500, dice.sim(3)))
Set2_9s <- Set2%>%
rename(sim2 = 1)%>%
filter(sim2 == 9)
count2_9 <- count(Set2_9s)
Set2_10s <- Set2%>%
rename(sim2 = 1)%>%
filter(sim2 == 10)
count2_10 <- count(Set2_10s)
### set 3
Set3<- data.frame(replicate(500, dice.sim(3)))
Set3_9s <- Set3%>%
rename(sim3 = 1)%>%
filter(sim3 == 9)
count3_9 <- count(Set3_9s)
Set3_10s <- Set2%>%
rename(sim3 = 1)%>%
filter(sim3 == 10)
count3_10 <- count(Set3_10s)
### Set 4
Set4<- data.frame(replicate(500, dice.sim(3)))
Set4_9s <- Set4%>%
rename(sim2 = 1)%>%
filter(sim2 == 9)
count4_9 <- count(Set4_9s)
Set4_10s <- Set2%>%
rename(sim4 = 1)%>%
filter(sim4 == 10)
count4_10 <- count(Set4_10s)
### Set5
Set5<- data.frame(replicate(500, dice.sim(3)))
Set5_9s <- Set5%>%
rename(sim2 = 1)%>%
filter(sim2 == 9)
count5_9 <- count(Set5_9s)
Set5_10s <- Set5%>%
rename(sim5 = 1)%>%
filter(sim5 == 10)
count5_10 <- count(Set5_10s)
simulation_test_1 <- tibble(
Total_of_9 = c(count1_9$n, count2_9$n, count3_9$n, count4_9$n, count5_9$n),
Total_of_10 = c(count1_10$n, count2_10$n, count3_10$n, count4_10$n, count5_10$n)
)
simulation_test_1
## # A tibble: 5 x 2
## Total_of_9 Total_of_10
## <int> <int>
## 1 63 69
## 2 44 58
## 3 56 58
## 4 52 58
## 5 65 59
Conclusion: This was a long way to get to the answer, however, according to the simulation when i ran it a dice sum of 10 was far more likely than a sum of 9. As a note, when building this simulation, there were times the sum of 9 was higher than the sum of 10 in all 5 runs.