If a large number of fair N-sided dice are rolled, the average of the simulated rolls is likely to be close to the mean of 1,2,...N i.e. the expected value of one die. For example, the expected value of a 6-sided die is 3.5.
Given N, simulate 1e8 N-sided dice rolls by creating a vector of 1e8 uniformly distributed random integers. Return the difference between the mean of this vector and the mean of integers from 1 to N.
The solution quits because it's taking too long. 1e8 is too many?
I discovered using a for loop doesn't work - too slow. Then I realised that randi can generate the required vector, doh!
Back to basics 8 - Matrix Diagonals
707 Solvers
Get the elements of diagonal and antidiagonal for any m-by-n matrix
199 Solvers
Replace multiples of 5 with NaN
282 Solvers
Replace every 3rd element in a vector with 4
124 Solvers
345 Solvers