# Riddler 2020-05-15

Two things are guaranteed to grab my attention in a Riddler Column - Dungeons and Dragons (DnD) and probability spaces small enough to enumerate all combinations.

The default position is roll 1 20-sided die (d20), and the other scenarios involve 4 d20 rolls, with a probability space of 20^4= 160,000. More than I’m willing to do by hand, but R laughs at how easy this is.

``````
die <- 1:20
all_combinations <- list(die_1 = die,die_2=die,die_3=die,die_4=die) %>%
cross_df()``````
``````result_table <- all_combinations %>%
dis_1 = pmin(die_1,die_2), dis_2=pmin(die_3,die_4)) %>%

Then the average for each is:

``````result_table %>%
summarise(default = mean(die_1),
knitr::kable()``````
10.5 11.16666 9.833338

The probability of getting exactly each roll is:

``````result_table %>%
pivot_longer(1:3) %>%
count(name,value) %>%
group_by(name) %>%
mutate(p=n/sum(n)) %>%
ungroup() %>%
ggplot(aes(x=value,y=p,colour=name)) + geom_line() +
scale_y_continuous(labels=scales::percent) +
expand_limits(y=0) +
theme_minimal()`````` Or the probability of getting at least N on the roll is:

``````result_table %>%