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 superlarge 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 mbyn matrix with previously calculated probabilities would help things?
Test  Status  Code Input and Output 

1  Pass 
%%
a = 3;
d = 0;
y_correct = 1.000;
assert(abs(risk_prob(a, d)  y_correct) <= 0.01)

2  Pass 
%%
a = 1;
d = 5;
y_correct = 0.000;
assert(abs(risk_prob(a, d)  y_correct) <= 0.01)

3  Pass 
%%
a = 5;
d = 3;
y_correct = 0.642;
assert(abs(risk_prob(a, d)  y_correct) <= 0.02)

4  Pass 
%%
a = 4;
d = 6;
y_correct = 0.134;
assert(abs(risk_prob(a, d)  y_correct) <= 0.02)

5  Pass 
%%
a = 10;
d = 10;
y_correct = 0.480;
assert(abs(risk_prob(a, d)  y_correct) <= 0.02)

6  Pass 
%%
a = 7;
d = 8;
y_correct = 0.329;
assert(abs(risk_prob(a, d)  y_correct) <= 0.02)

7  Pass 
%%
a = 8;
d = 7;
y_correct = 0.5355;
assert(abs(risk_prob(a, d)  y_correct) <= 0.02)

8  Pass 
%%
a = 20;
d = 10;
y_correct = 0.965;
assert(abs(risk_prob(a, d)  y_correct) <= 0.02)

9  Pass 
%%
a = 4;
d = 2;
y_correct = 0.656;
assert(abs(risk_prob(a, d)  y_correct) <= 0.02)

10  Pass 
%%
a = 6;
d = 4;
y_correct = 0.638;
assert(abs(risk_prob(a, d)  y_correct) <= 0.02)

11  Pass 
%%
a = 2;
d = 1;
y_correct = 0.417;
assert(abs(risk_prob(a, d)  y_correct) <= 0.02)

12  Pass 
%%
a = 2;
d = 2;
y_correct = 0.104;
assert(abs(risk_prob(a, d)  y_correct) <= 0.02)

Remove any row in which a NaN appears
6622 Solvers
580 Solvers
Is this number Munchhausen Narcissistic?
134 Solvers
39 Solvers
157 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!