Cody

# Problem 1301. RISK Calculator - Large Armies, High Accuracy, Fast

This Challenge is to quickly provide the high precision probability of legal RISK battles up to 100 vs 100. [ Attack >= 2 and Defense >=1 ].

Link to official Risk Rules

Simplified explanation of the dice play:

```Attacker with 2 armies will throw one die.
Attacker with 3 armies will throw two die.
Attacker with 4 or more armies will throw three die.
```
```Defense with 1 army will use one die.
Defense with 2 or more armies will throw 2 die.
```
```The attacker High is compared to the Defender High.
If Attacker High > Defender High then defender loses 1 army otherwise Attacker loses 1 army. Tie goes to defender.
If the Defender threw two die and the Attacker threw 2 or more die then the Second Highest of each is compared.
If Attack > Defense then Defense loses an army otherwise Attack loses an army.
Attack continues until No defenders remain (Win) or Attack is reduced to 1 army (Lose).
```

Input: a,d where a is number of attacking armies and d is number defending

Output: pwin, the probability of the Attacker Winning

Accuracy: Accurate to +/- 1e-6

Scoring: Time (msec) to solve 10 Battle Scenarios

Risk Calculator

### Solution Stats

21.74% Correct | 78.26% Incorrect
Last solution submitted on Nov 16, 2015

### Problem Comments

Tags

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

### Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

### MATLAB Academy

New to MATLAB?

Learn MATLAB today!

#### Join the 15-year community celebration.

Play games and win prizes!

Learn more