Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

R source will be acceptable too. Suppose you are a board game maker, and you wan

ID: 3207222 • Letter: R

Question

R source will be acceptable too.

Suppose you are a board game maker, and you want to give players a higher probability ofrolling larger numbers. Originally you had them roll three six-sided dice and add their results. The new approach will have the player roll four dice and add the totals of the three highest valued dice. Write a program that counts through every permutation of four six-sided dice and find the total of the three highest valued dice. Calculate the permutations of rolling four six-sided dice Plot a histogram of the totals Calculate the mean and standard deviation of the totals Plot a histogram of the values for the lowest valued, second-lowest, third- lowest, and highest value dice

Explanation / Answer

# Used R for the solution as its mentioned that R is acceptable too.
# Preparing the data for 4 draws
d1 <- 1:6
d2 <- 1:6
d3 <- 1:6
d4 <- 1:6

# Converting draws to data frames
d1_t = data.frame(d1)
d2_t = data.frame(d2)
d3_t = data.frame(d3)
d4_t = data.frame(d4)

# Use the following install statements if needed
#install.packages("sqldf")
#install.packages("reshape2")

# Using sqldf library to cross join the draws (d1_t-d4_t)
library(sqldf)
choices = sqldf("select * from d1_t, d2_t, d3_t, d4_t")
choices$choice_id = as.character(row.names(choices))

# Answer A: Here is the permutation of all the rolling 4 Six-sided dice. (Data Frame choices)
choices


library(reshape2)
choices.melted<-melt(choices)
choices.sorted <- choices.melted[order(choices.melted$choice_id,-choices.melted$value),]
choices.first3 <- choices.sorted[-seq(4,to = nrow(choices.sorted),by = 4),]

# Below dataset contains total of highest 3 draws of all the permutations
choices.first3.sum <- aggregate(choices.first3$value,by=list(Choice_id = choices.first3$choice_id),FUN = sum)

# Ans B: Histogram of the total
hist(choices.first3.sum$x)

# Ans C: Mean and SD of totals of highest 3 draws
mean(choices.first3.sum$x)
sd(choices.first3.sum$x)

# Ans D: Histograms for lowest, 2nd lowest, 3rd lowest and highest dice respectively:
hist(choices.sorted[seq(1,to = nrow(choices.sorted),by = 4),]$value)
hist(choices.sorted[seq(2,to = nrow(choices.sorted),by = 4),]$value)
hist(choices.sorted[seq(3,to = nrow(choices.sorted),by = 4),]$value)
hist(choices.sorted[seq(4,to = nrow(choices.sorted),by = 4),]$value)