### A die is rolled three times. Find the probability that the sum of the outcomes is (a) greater than 9. (b) an odd number.

library(tidyverse)
## -- Attaching packages ----------------------------------------------------------- tidyverse 1.2.1 --
## v ggplot2 3.1.1       v purrr   0.3.2
## v tibble  2.1.1       v dplyr   0.8.0.1
## v tidyr   0.8.3       v stringr 1.4.0
## v readr   1.3.1       v forcats 0.4.0
## -- Conflicts -------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::lag()    masks stats::lag()
dies.3<-data.frame()
for(i in 1:6) {
for(j in 1:6) {
for(k in 1:6){
dies.3<-rbind(dies.3,i+j+k)
}
}
}

# a) Calculate probability that sum of 3 tosses of a dice is greater than 9
names(dies.3)<-'total'
dies.3.df<-data.frame(table(dies.3$total)) #(dies.3.df) total<-sum(dies.3.df$Freq)
dies.gt.9<-dies.3.df%>%filter(dies.3.df$Var1%in%c(10,11,12,13,14,15,16,17,18)) #dies.gt.9 total.gt.9<-sum(dies.gt.9$Freq)/total
cat("The probability that the sum of outcomes of 3 tosses of a dice is greater than 9 is", total.gt.9, "\n")
## The probability that the sum of outcomes of 3 tosses of a dice is greater than 9 is 0.625
# b) Calculate probability that sum of 3 tosses of a dice is an odd number
odd.numbers<-seq(1,18,2)
dies.odd.nos<-dies.3.df%>%filter(dies.3.df$Var1%in%odd.numbers) #dies.odd.nos total.odd.nos<-sum(dies.odd.nos$Freq)/total
cat("The probability that the sum of outcomes of 3 tosses of a dice is an odd number is", total.odd.nos, "\n")
## The probability that the sum of outcomes of 3 tosses of a dice is an odd number is 0.5