Can you double check your values, Jeremy? I've run your sims against a couple of on-line Risk calculators, and they're coming up with different values for some of your test cases. For example, the one at http://recreationalmath.com/Risk/ using 10 attackers and 10 defenders comes up with 0.47993525647768026, which doesn't meet your error criteria.
Thanks, James, you were right - I generated the values myself with a Matlab script. Unfortunately I did not do enough simulations - 10000 doesn't always get within 1% accuracy. Have updated them all now and rescored all solutions too.
Your solution is now the leading solution btw :)
I didn't submit a solution yet...mainly because I couldn't match up your test values and wanted to make sure that the problem wasn't on my end. (Most of the time, it is! :-)
I've got a working submission now, but you'll need to check the high end of the size chart for it. As usual, Richard and Alfnie are far more clever than I.
James, you give me too much credit. The next ot best solution was a very minor tweak to Jeremy's random solver. My larger solutions, 250, find the exact solution recursively.
James, your speed is impacted by recalculating previously evaluated cases. A case of 100 v 100 finished in ??
You're correct. It is inefficient with super-large armies. I was going for an exact solution (which was an offshoot of the original problems I had with the test suite), and recursion seemed to be the best way to do it.
As our resident "Get this problem to run faster" expert, do you think setting up a global m-by-n matrix with previously calculated probabilities would help things?
suggest writing script to produce testsuite of more cases to paste into cody
Yes, I am enlarging the test suite. Thanks for the input!
random picture with random colours
Back to basics 19 - character types
Make a random, non-repeating vector.
Check if number exists in vector
Getting the indices from a matrice
Determine the number of odd integers in a vector
Penny flipping - calculate winning probability (easy)
It's race time! Write a faster function than the test suite call of unique().
Create matrix of replicated elements
Who is the smartest MATLAB programmer?
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