# This code performs a simulation for the "ice cream dice prices" example. # # first simulate rolling two dice 10000 times d1 = sample(1:6,10000, replace=TRUE) d2 = sample(1:6,10000, replace=TRUE) # # next determine the price from the dice rolls price = 10*pmax(d1,d2) + pmin(d1,d2) # # now determine whether the price is affordable afford=(price<=50) # # calculate the proportion of times that the price is affordable sum(afford)/10000