This was my simple method simply generating every possible roll using the function `expand.grid` in R, then summing, and finding the number with scores >= 7 (and other scores as well as other number of dice).
Code:
library(tidyverse)
faces <- c(0, 1, 2)
max_dice_needed <- 8
max_score_needed <- 12
results <-
data.frame(dice = numeric(),
score_needed = numeric(),
prob = numeric())
for(k in 1:max_dice_needed){
ndice <- k
dice <- list()
# add number of dice to list
for (i in 1:ndice){
dice <- append(dice, list(faces))
}
# find every permutation of dice faces
rolls <- expand.grid(dice)
# calculate total score for the throw
scores <-
rolls %>%
rowwise %>%
mutate(score = sum(c_across(starts_with("Var")))) %>%
pull(score)
message("dice:", ndice, " scores:", length(scores))
# calculate probability of getting >= required score
for(j in 0:max_score_needed){
score_needed <- j
results <-
rbind(results,
data.frame(dice = ndice,
score_needed = j,
prob = mean(scores >= score_needed)
)
)
}
}
# plot results
results %>%
mutate(dice = factor(dice)) %>%
ggplot(aes(x = score_needed, y = prob, colour = dice))+
geom_point()+
geom_line()+
geom_label(aes(label = dice))+
scale_x_continuous(breaks = scales::pretty_breaks(n = 12))+
scale_y_continuous(breaks = scales::pretty_breaks(n = 10),
labels = scales::percent)+
labs(y = "probability", x = "score needed")+
theme(legend.position = "none")
ggsave("probabilities.png")
Another method I had was to consider the number of combinations of dice that made up 7 or higher, i.e.:
7: 2, 2, 2, 1, 0 - 5!/3!
7: 2, 2, 1, 1, 1 - 5!/(2! x 3!)
8: 2, 2, 2, 2, 0 - 5!/4!
8: 2, 2, 2, 1, 1 - 5!(2! x 3!)
9: 2, 2, 2, 2, 1 - 5!/4!
10: 2, 2, 2, 2, 2 - 1
then (5!/3! + 5!/(2! x 3!) + 5!/4! + 5!(2! x 3!) + 5!/4! + 5!/4! + 1) / 3^5 = 20.99%