The solution quits because it's taking too long. 1e8 is too many?
The difference should essentially be zero i.e. the two averages equal. I wrote a successful script; run in my desktop environment but the tool won't accept my answer as valid.
It crashes every time, how to complete it?
To get this right apparently you have to generate the random numbers exactly the same way as the answer key. When it tests your script it seeds the random number generator and then confirms whether your program gets EXACTLY the same result. However, if you generate the random numbers in any way different from the key, your answer will be "wrong" but is probably still correct.
There is a MatLab function that does it. Nice and easy.
"1e8 N-sided dice" made me confused. I think it should be changed to "1e8-sided dice".
this problem brakes the website. 1e8 is too big and the website blocks out my computer.
After multiple tries of submitting what i thought the correct answer and being met with "While evaluating the solution, the server encountered an error caused by temporary unavailability of MATLAB Service. Wait a few minutes for the MATLAB Service to return, and then rescore." what seemed to do the trick was what Marcel Dornbusch hinted in his comment.
Just make sure you do not output every bit of information in the code, and just output the answer.
I created a "step by step" solution that was not accepted. Then I reformulated this solution for compound formula end, voila, it was accepted.
I don't know why every time I send the solution the site show me: "While evaluating the solution, the server encountered an error caused by temporary unavailability of MATLAB Service. Wait a few minutes for the MATLAB Service to return, and then rescore."
function dice_diff = loln(N)
%N-sided dice , 1e8 times rolling
dice_diff =mean(randi(N,1e8,1)) - ((N+1)/2);
function dice_diff = loln(N)
%the mean of integer from 1 to N
A = 1:N;
meanN = mean(A);
V = randi(N, 1e8,1);
meanvector = mean(V);
dice_diff = meanvector - meanN;
For saving execution time, do without outpout! Then it worked for me.
what is the problem with this solution
Note that using rand() with round() will not produce the correct answer. There is another function that must be used instead.
What can be used? I am a bit confused.
1e8 is too big for the Matlab website. It crashes every time I try it. I managed to find a solution on the full version so I put it in comments and cheated to pass it.
I discovered using a for loop doesn't work - too slow. Then I realised that randi can generate the required vector, doh!
Can anyone do that in a size smaller than 22? That was the smallest size I could get.
The Goldbach Conjecture
Find the palindrome
Get the area codes from a list of phone numbers
Relative ratio of "1" in binary number
Matlab Basics - Absolute Value
Plot Line Specifications
Calculate Amount of Cake Frosting
Convert from Fahrenheit to Celsius
Calculate Inner Product
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office