Post Reply 
Dice probabilities
04-29-2024, 07:22 PM
Post: #6
RE: Dice probabilities
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%
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Dice probabilities - dm319 - 04-29-2024, 04:23 PM
RE: Dice probabilities - Thomas Klemm - 04-29-2024, 04:55 PM
RE: Dice probabilities - Allen - 04-30-2024, 11:19 AM
RE: Dice probabilities - dm319 - 04-29-2024, 05:49 PM
RE: Dice probabilities - Thomas Klemm - 04-29-2024, 06:07 PM
RE: Dice probabilities - David Hayden - 04-30-2024, 07:30 PM
RE: Dice probabilities - Albert Chan - 04-30-2024, 08:26 PM
RE: Dice probabilities - dm319 - 04-30-2024, 09:57 PM
RE: Dice probabilities - dm319 - 04-29-2024, 07:14 PM
RE: Dice probabilities - Albert Chan - 04-29-2024, 09:22 PM
RE: Dice probabilities - dm319 - 04-30-2024, 10:07 PM
RE: Dice probabilities - Albert Chan - 05-01-2024, 11:14 AM
RE: Dice probabilities - dm319 - 04-29-2024 07:22 PM
RE: Dice probabilities - Gil - 04-29-2024, 10:36 PM
RE: Dice probabilities - Thomas Klemm - 04-30-2024, 12:27 AM
RE: Dice probabilities - John Keith - 04-30-2024, 10:00 PM
RE: Dice probabilities - Thomas Klemm - 04-30-2024, 12:40 AM
RE: Dice probabilities - Thomas Klemm - 04-30-2024, 06:43 AM
RE: Dice probabilities - Thomas Klemm - 04-30-2024, 08:06 AM
RE: Dice probabilities - Albert Chan - 04-30-2024, 10:59 AM
RE: Dice probabilities - Dave Britten - 04-30-2024, 12:00 PM
RE: Dice probabilities - Thomas Klemm - 04-30-2024, 05:11 PM
RE: Dice probabilities - Dave Britten - 04-30-2024, 05:58 PM
RE: Dice probabilities - Thomas Klemm - 04-30-2024, 06:04 PM
RE: Dice probabilities - Thomas Klemm - 04-30-2024, 06:25 PM
RE: Dice probabilities - Dave Britten - 04-30-2024, 07:24 PM
RE: Dice probabilities - Thomas Klemm - 04-30-2024, 09:10 PM
RE: Dice probabilities - Thomas Klemm - 05-01-2024, 03:32 AM
RE: Dice probabilities - Thomas Klemm - 05-01-2024, 04:26 AM
RE: Dice probabilities - Thomas Klemm - 05-01-2024, 04:41 AM
RE: Dice probabilities - John Keith - 05-01-2024, 06:56 PM
RE: Dice probabilities - Thomas Klemm - 05-01-2024, 05:54 AM
RE: Dice probabilities - Thomas Klemm - 05-01-2024, 08:45 PM
RE: Dice probabilities - John Keith - 05-02-2024, 02:46 PM
RE: Dice probabilities - Albert Chan - 05-03-2024, 01:08 PM
RE: Dice probabilities - Thomas Klemm - 05-03-2024, 01:20 AM



User(s) browsing this thread: 1 Guest(s)