Anydice help with irregular dice pool [duplicate]

Here's the gist of it:

I roll a number of different size die like 2d6, 2d8 and 1d12, looking for the highest die. I found a nifty Anydice program that helped me understand the probabilities like this. However, I'd like to know how the probabilities change when I apply a disadvantage mechanic as follows:

I roll the pool. Being at a disadvantage, I remove the highest rolled die (not the highest size die) and then go to the second highest rolled die. For instance, using the above pool the results are: 2, 2, 4, 5 and 12. I remove the 12 and the highest result is now 5.

Can someone help me with these probabilities?

You can do this with relatively few changes to that code you found.

The first change is to add a parameter for which die to pick, ie. the Nth highest. This isn't strictly necessary if you only ever care about the second, but it'll make things cleaner at least.

The second change is to keep the other results from your subpools. In the original, the second highest d8 (as an example) is never passed to the function, but it could of course be the second highest die result. We therefore change the function input to sequences (:s) and concat the sequence, sort and pick the Nth in the sequence (N@).

Then to make our own life easier we can use a loop for the outputs, so that we test each value of N. The highest (sensible) value of N would be the number of dice in your pool.

function: N:n th of A:s B:s C:s D:s{
result: N@[sort {A, B, C, D}]
}

loop N over {1..5} {output [N th of 0d4 2d6 2d8 1d12] named "[N] highest of pool"}


Which you can play around with here.