## This is a considerably hard analytical problem

The question you linked, although already quite hard, is easier because it can be computed as the probability of a dice being in one set, and not in the other. In your question, this is done in a one-to-one basis, as you mentioned, and this is a considerably hard problem.

## Doesn’t matter – do it the easy way

Unless you need the analytical expression for something, I recommend going with Monte Carlo:

You basically run a random simulation **a bunch** of times, and then see the distribution of that. This code for MATLAB does it – I am sure someone can translate it to Python or something that doesn’t need to be paid, but I’m more familiar with MATLAB haha

```
N_it = 10^5;
N_action = 6;
N_danger = 5;
bins = 1:6;
for i = 1:N_it
Action_Dice = randi((1 6), N_action, 1);
Danger_Dice = randi((1 6), N_danger, 1);
Action_Dice_Count = hist(Action_Dice, bins);
Danger_Dice_Count = hist(Danger_Dice, bins);
Result_Count = Action_Dice_Count - Danger_Dice_Count;
Result = find(Result_Count > 0, 1, 'last');
if(Result)
Result_Save(i) = Result;
else
Result_Save(i) = 0;
end
end
```

So, what this code does is basically: roll a set number of action dice and danger dice, count how many of each dice you got, subtract the number of rolled danger dice from the number of rolled action dice, then find the last value which is non-zero (i.e., the highest Action Dice remaining) and finally, if no such action dice exists, it sets the result to 0.

As an example, for 6 Action Dice and 5 Danger Dice, this is what it looks like:

Why does it look like this? In the example, I used 6 action dice and 5 danger dice. The probability that there is no remaining action dice is, evidently, zero, since we will always have one remaining dice. But not only that, there is a high probability on 6, why? Because every time there is a 6 remaining, that 6 will be chosen. This is actually an easier analytical problem. Let $X$ denote the number of sixes appearing in the Action Dice pool, and $Y$ be the number of sixes appearing in the Danger Dice pool. We are interested in $P(X > Y)$. But what is nice in this case is that we know the exact distribution of both $X$ and $Y$, which are binomial distributions with the number of trials being equal to the number of dice in the pool, and probability in each trial equal to 1/6.

We can then compute $P(X – Y)$, which can be done by the convolution of $P(X)$ and $P(-Y)$, and finally compute $P(X – Y > 0)$. I won’t bother with all this computation here, but if you do it, you will find out that the probability is 0.383367984110654. The probability found by code was 0.386, so, close enough, the code seems to make sense.

Note that this same strategy of analytically computing the other probabilities will not help for other values than 6, since, not only you need that, for example, the number of fives in the Action pool should be larger than the number in the Danger pool, you also need that the number of sixes in the action pool is smaller than or equal to the number in the danger pool. For 5 it is already a bunch of complicated conditional probabilities, and it will get harder and harder for lower numbers, since each time you need to consider the numbers above it.

## Validating the Code

I can only think about one trivial case, so we can check whether the code makes sense for that case at least. Consider only 1 Action Dice and 1 Danger Dice. In this case, the probability that they are equal is 1/6, and in that case the result is 0 (i.e., no action dice remaining). Otherwise, we have an equal probability for any dice, which is 5/36.

The values resulting from the code are, in fact, approximately 1/6 for 0 and 5/36 for the remaining.