Statistics on dice rolls with "keep highest", "keep lowest" and "reroll if value is below x" gimmick I am trying to calculate some statistics about dicerolls where we have the "keep highest", "keep lowest" and "reroll values below x" gimmick.
I have worked out the statistics for using a single type of dice but I am having some issues with determining the chance of hitting the target value when mixing multiple types of dice and gimmicks. I want to figure out an effective way of calculating the chance that doesn't require me to check all the possibilities.
I am trying to figure out a elegant method to do this.
example: rolling 2 d20's keeping the lowest and rolling 2 d4's keeping the highest. add the lowest d20 with the highest d4 and compare it with a target of 15. This gives me a chance of 21.03125% of hitting a result that is equal to or higher than 15.
(I roll a 18 and a 5 on my d20's. I keep the 5. I roll a 1 and a 4 on my d4's. I keep the 4. I add the 5 to the 4 and get 9. 9 is lower than 15 thus this roll failed.)
How can I calculate this without checking every possibility?
edit: removed the code part. I used it to exemplify my problem and I expanded the example
 A: Note that rolling a fair dice with $f$ faces numbered $1,...,f$ and rerolling it if the result is lower than $x$ is equivalent with rolling a fair dice with $f - x + 1$ faces numbered $x,...,f$. So you can take this into account and improve your code a bit.
To be honest, I am not sure that the code is very good so you could perhaps explain advantage and also the example you gave? I think by combine you mean the probability that the sum of the rolls is no less than the target value?
Edit: To better answer after the question was edited as well
Let $N$ be the number of the not necessarily identical (but fair?) dices, $T$ be the target value, $f_i$ be the number of faces of the $i$-th dice and $x_i$ be its rollout threshold. We are looking for the probability:
$$p = P[\sum_{i=1}^{N}roll(i) \ge T]$$
Firstly, we can compute the number of different ways to write $T$ as a sum of $N$ non zero integers. That can be done in $O(2^N)$ time. For every way it can be done we write:
$$ T = t_1 + ... + t_N = \sum_{i=1}^{N}t_i \implies p = P[\sum_{i=1}^{N}roll(i) \ge \sum_{i=1}^{N}t_i]$$
Since dices aren't dependent(again I am assuming this), we can write:
$$ p = \prod_{i=1}^{N}P[roll(i) \ge t_i] $$
Now, let's fix a dice $i$(and simplify the notation). We want the probability $q = P[roll \in [t, f]]$. If $t > f$ or $t < x$ then $q = 0$. Differently, $q = \frac{f-t+1}{f-x+1}$. Putting everything together, $q$ can be calculated in constant time, therefore $p$ in $O(N)$ for a total running time of $O(N2^N)$, which drops to $ O(N^2\cdot 2^N)$ for dropping the double counting or working with equalities.
To address the min-max gimmicks, assume that a single dice from above, can be replace by a dice group, on which you will apply the min or max function. When you apply the min the calculation is pretty straightforward. Notice that $P[min(a,b) \ge t] = P[\{a \ge t\} \cup \{b \ge t\}] = P[\{a \ge t\}]\times P[\{b \ge t\}]$ thus the $q$ of a dice group under min is simply the product of the $q$'s of every single dice. The calculation for max is bit harder since instead of an intersection you get a union so you must use the identity for the probability of a union of $k$ sets.
That was quite general. If you can specify your gimmicks and your parameters more it can be more specific. Also, you can improve performance for sure, I just gave naive bounds.
