AnyDice
To choose the best numbers to reach the DC, we can use an exhaustive search. There are only ten ways to choose two of five dice, which is pretty manageable by itself.
function: remaining A:n and B:n and C:n and D:n and E:n vs DC:n {
ROLLS: {A, B, C, D, E}
RESULT: -1
loop I over {1..5} {
loop J over {I+1..5} {
if I@ROLLS & J@ROLLS & {I,J}@ROLLS >= DC {
RESULT: [highest of RESULT and ROLLS - {I,J}@ROLLS]
}
}
}
result: RESULT
}
output [remaining d12 and d8 and d8 and d6 and 0 vs 10]
AnyDice link.
Here we loop over all possible choices of two dice to use to reach the DC, and pick the one that has the highest sum of remaining dice. We use arguments of zero to represent rolling fewer than five dice, and exclude using them to reach the DC. (I interpret your question as meaning you must choose exactly two dice to use to reach the DC, even if just one would have been sufficient.) ROLLS - {I,J}@ROLLS
implicitly sums ROLLS
and the two selected dice before finding the difference.
Icepool
Unfortunately, while AnyDice is capable of efficiently expanding pools of one type of die into sorted sequences, it can't store mixed pools in variables (which is why we used a separate parameter for each die), nor efficiently expand them. As such, if you use the 5th die it's likely it will time out. My Icepool Python probability package can efficiently expand mixed pools from a single variable:
from icepool import d, map_function, Pool
from itertools import combinations
@map_function
def remaining(rolls, dc):
used = [sum(t) for t in combinations(rolls, 2)]
return max((sum(rolls) - x for x in used if x >= dc), default=-1)
pool = Pool([d(12), d(8), d(8), d(6)])
output(remaining(pool, 10))
Here we use itertools.combinations
to pick two of the numbers but not the same die twice. Then the next line picks the optimal sum. Finally, the map_function
decorator causes the function to run over all possible multisets of numbers that could come out of the pool, similar to how AnyDice expands pools to sequences.
You can try this in your browser here.