Question: a)Using the Monte Carlo simulator provided below write a function called diceDiff() that rolls two 6 sided die and returns the difference between the larger
a)Using the Monte Carlo simulator provided below write a function called diceDiff() that rolls two 6 sided die and returns the difference between the larger and smaller values.
b) Again using the Monte Carlo simulator, write a second function diceDiff(dieSide, die2Side = 0) that takes the difference between two die that have differing number of sides. If die2Side is zero, use the value of dieSide as its value.
####################### Monte Carlo Simulator #############################
monteCarloSimulation <- function(n = 1, mcSystem, measure = identity, mode = "numeric", printIter = function(iteration){}) { iteration <- vector(mode, n) for(i in 1:n){ iteration[[i]] <- mcSystem() printIter(iteration[[i]]) } return(measure(iteration)) }
### very simple version of an iteration printer mcPrintIter <- function(iteration){ print(iteration) }
### To be used with the simulation.replications() function monteCarloEnv <- function(n = 1, mcSystem, measure = identity, mode = "numeric", printIter = function(iteration){}) { # touch all variables so lazy eval will colapse promise and not store variable instead of value in the enviroment n; mcSystem; measure; mode; printIter environment() }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
