AnyDice can, in fact, do this.
The tricky part, as noted in Dale M's answer, is indicating "how many action dice are left and what the values of those dice are", since AnyDice can only output probability distributions over numbers, not over sequences of numbers. But we can get around this with a helper function that encodes a sequence as the digits of a number:
function: encode SEQUENCE:s in base BASE:n {
NUMBER: 0
loop DIGIT over SEQUENCE {
NUMBER: BASE * NUMBER + DIGIT
}
result: NUMBER
}
For example, calling this function as [encode {3,1,4,1,5,9} in base 10]
will return the number 314159. Since any d6 roll fits nicely as a single base 10 digit, that works fine for our purposes here. (If you wanted to try using, say, a d12 or a d20, you could use the same encoding function, but with base 100 instead.)
With this encoding issue dealt with, we can then write our actual code. As usual, when implementing any nontrivial dice-counting mechanic in AnyDice, we need to write a function that takes a sequence parameter (or two, in this case) and let AnyDice call it for all possible rolls of a dice pool (or two):
function: ACTION:s action STRESS:s stress {
\ Loop over the ACTION dice, canceling any with an equal or higher STRESS roll if possible, keep the rest. \
\ Note that this algorithm relies on the ACTION and STRESS sequences both being sorted in descending order! \
KEEP: {}
INDEX: 1 \ This index points to the first (i.e. highest) stress die not yet used. \
loop DIE over ACTION {
if INDEX <= #STRESS & INDEX@STRESS >= DIE {
INDEX: INDEX + 1 \ Cancel this action die, move index to next stress die. \
} else {
KEEP: {KEEP, DIE} \ Keep this action die, don't move index. \
}
}
\ We cannot return a sequence from a function auto-summed over a die, so we must encode it as a number. \
result: [encode KEEP in base 10]
}
output [5d6 action 3d6 stress]
This code loops over the action dice in descending numerical order (as AnyDice sorts dice pools by default), checking each one against the highest stress die not yet used. If the stress die is equal to or higher than the action die, we let those two dice cancel out (and update the INDEX
variable to point to the next highest stress die); if it's not, we add the uncancelled action die to the KEEP
sequence, which we return (encoded as a number) in the end.
(Note that we don't explicitly return the number of remaining dice, since you can just read that from the number of digits in the result.)
FWIW, the output of this code, exported and reformatted as a Markdown table, looks like this:
Remaining dice |
Probability (%) |
11 |
5.8103161675 |
21 |
5.81263812681 |
22 |
2.90602137631 |
31 |
3.52461515013 |
32 |
2.88726708962 |
33 |
2.06797267947 |
41 |
3.03819444444 |
42 |
1.87513098232 |
43 |
2.18561861759 |
44 |
1.96842611645 |
51 |
3.52461515013 |
52 |
1.87513098232 |
53 |
1.64561423563 |
54 |
2.36274243637 |
55 |
2.46740921734 |
61 |
5.81263812681 |
62 |
2.88726708962 |
63 |
2.18561861759 |
64 |
2.36274243637 |
65 |
3.78479366712 |
66 |
4.36266384697 |
222 |
0.339958657217 |
322 |
0.606388603109 |
332 |
0.548339620485 |
333 |
0.421286770309 |
422 |
0.392946959305 |
432 |
0.621570644719 |
433 |
0.764460448102 |
442 |
0.379551040238 |
443 |
0.70016003658 |
444 |
0.498090039628 |
522 |
0.379551040238 |
532 |
0.475108596251 |
533 |
0.560842478281 |
542 |
0.475108596251 |
543 |
0.864483310471 |
544 |
0.99576331733 |
552 |
0.392946959305 |
553 |
0.560842478281 |
554 |
0.943072702332 |
555 |
0.699445587563 |
622 |
0.548339620485 |
632 |
0.621570644719 |
633 |
0.70016003658 |
642 |
0.475108596251 |
643 |
0.864483310471 |
644 |
0.943072702332 |
652 |
0.621570644719 |
653 |
0.864483310471 |
654 |
1.46462048468 |
655 |
1.70396090535 |
662 |
0.606388603109 |
663 |
0.764460448102 |
664 |
0.99576331733 |
665 |
1.70396090535 |
666 |
1.27945911446 |
2222 |
0.010121361073 |
3222 |
0.0306617703094 |
3322 |
0.0428669410151 |
3332 |
0.027982586496 |
3333 |
0.028756572931 |
4222 |
0.0226242188691 |
4322 |
0.060728166438 |
4332 |
0.060728166438 |
4333 |
0.0857338820302 |
4422 |
0.0321502057613 |
4432 |
0.0571559213535 |
4433 |
0.119670210334 |
4442 |
0.0217311575979 |
4443 |
0.078589391861 |
4444 |
0.0503686556927 |
5222 |
0.0217311575979 |
5322 |
0.0500114311843 |
5332 |
0.048225308642 |
5333 |
0.0678726566072 |
5422 |
0.048225308642 |
5432 |
0.0821616369456 |
5433 |
0.175040009145 |
5442 |
0.0500114311843 |
5443 |
0.175040009145 |
5444 |
0.158071844993 |
5522 |
0.0321502057613 |
5532 |
0.048225308642 |
5533 |
0.0982367398262 |
5542 |
0.048225308642 |
5543 |
0.167895518976 |
5544 |
0.225051440329 |
5552 |
0.0226242188691 |
5553 |
0.0678726566072 |
5554 |
0.150034293553 |
5555 |
0.0854957323579 |
6222 |
0.027982586496 |
6322 |
0.060728166438 |
6332 |
0.0571559213535 |
6333 |
0.078589391861 |
6422 |
0.048225308642 |
6432 |
0.0821616369456 |
6433 |
0.175040009145 |
6442 |
0.048225308642 |
6443 |
0.167895518976 |
6444 |
0.150034293553 |
6522 |
0.0571559213535 |
6532 |
0.0821616369456 |
6533 |
0.167895518976 |
6542 |
0.0821616369456 |
6543 |
0.278635116598 |
6544 |
0.385802469136 |
6552 |
0.060728166438 |
6553 |
0.175040009145 |
6554 |
0.385802469136 |
6555 |
0.304831580552 |
6622 |
0.0428669410151 |
6632 |
0.060728166438 |
6633 |
0.119670210334 |
6642 |
0.0500114311843 |
6643 |
0.175040009145 |
6644 |
0.225051440329 |
6652 |
0.060728166438 |
6653 |
0.175040009145 |
6654 |
0.385802469136 |
6655 |
0.450102880658 |
6662 |
0.0306617703094 |
6663 |
0.0857338820302 |
6664 |
0.158071844993 |
6665 |
0.304831580552 |
6666 |
0.160751028807 |
22222 |
0.0000595374180765 |
32222 |
0.000297687090383 |
33222 |
0.000595374180765 |
33322 |
0.000595374180765 |
33332 |
0.000297687090383 |
33333 |
0.000476299344612 |
42222 |
0.000297687090383 |
43222 |
0.00119074836153 |
43322 |
0.0017861225423 |
43332 |
0.00119074836153 |
43333 |
0.00238149672306 |
44222 |
0.000595374180765 |
44322 |
0.0017861225423 |
44332 |
0.0017861225423 |
44333 |
0.00476299344612 |
44422 |
0.000595374180765 |
44432 |
0.00119074836153 |
44433 |
0.00476299344612 |
44442 |
0.000297687090383 |
44443 |
0.00238149672306 |
44444 |
0.00160751028807 |
52222 |
0.000297687090383 |
53222 |
0.00119074836153 |
53322 |
0.0017861225423 |
53332 |
0.00119074836153 |
53333 |
0.00238149672306 |
54222 |
0.00119074836153 |
54322 |
0.00357224508459 |
54332 |
0.00357224508459 |
54333 |
0.00952598689224 |
54422 |
0.0017861225423 |
54432 |
0.00357224508459 |
54433 |
0.0142889803384 |
54442 |
0.00119074836153 |
54443 |
0.00952598689224 |
54444 |
0.00803755144033 |
55222 |
0.000595374180765 |
55322 |
0.0017861225423 |
55332 |
0.0017861225423 |
55333 |
0.00476299344612 |
55422 |
0.0017861225423 |
55432 |
0.00357224508459 |
55433 |
0.0142889803384 |
55442 |
0.0017861225423 |
55443 |
0.0142889803384 |
55444 |
0.0160751028807 |
55522 |
0.000595374180765 |
55532 |
0.00119074836153 |
55533 |
0.00476299344612 |
55542 |
0.00119074836153 |
55543 |
0.00952598689224 |
55544 |
0.0160751028807 |
55552 |
0.000297687090383 |
55553 |
0.00238149672306 |
55554 |
0.00803755144033 |
55555 |
0.0038103947569 |
62222 |
0.000297687090383 |
63222 |
0.00119074836153 |
63322 |
0.0017861225423 |
63332 |
0.00119074836153 |
63333 |
0.00238149672306 |
64222 |
0.00119074836153 |
64322 |
0.00357224508459 |
64332 |
0.00357224508459 |
64333 |
0.00952598689224 |
64422 |
0.0017861225423 |
64432 |
0.00357224508459 |
64433 |
0.0142889803384 |
64442 |
0.00119074836153 |
64443 |
0.00952598689224 |
64444 |
0.00803755144033 |
65222 |
0.00119074836153 |
65322 |
0.00357224508459 |
65332 |
0.00357224508459 |
65333 |
0.00952598689224 |
65422 |
0.00357224508459 |
65432 |
0.00714449016918 |
65433 |
0.0285779606767 |
65442 |
0.00357224508459 |
65443 |
0.0285779606767 |
65444 |
0.0321502057613 |
65522 |
0.0017861225423 |
65532 |
0.00357224508459 |
65533 |
0.0142889803384 |
65542 |
0.00357224508459 |
65543 |
0.0285779606767 |
65544 |
0.048225308642 |
65552 |
0.00119074836153 |
65553 |
0.00952598689224 |
65554 |
0.0321502057613 |
65555 |
0.0190519737845 |
66222 |
0.000595374180765 |
66322 |
0.0017861225423 |
66332 |
0.0017861225423 |
66333 |
0.00476299344612 |
66422 |
0.0017861225423 |
66432 |
0.00357224508459 |
66433 |
0.0142889803384 |
66442 |
0.0017861225423 |
66443 |
0.0142889803384 |
66444 |
0.0160751028807 |
66522 |
0.0017861225423 |
66532 |
0.00357224508459 |
66533 |
0.0142889803384 |
66542 |
0.00357224508459 |
66543 |
0.0285779606767 |
66544 |
0.048225308642 |
66552 |
0.0017861225423 |
66553 |
0.0142889803384 |
66554 |
0.048225308642 |
66555 |
0.038103947569 |
66622 |
0.000595374180765 |
66632 |
0.00119074836153 |
66633 |
0.00476299344612 |
66642 |
0.00119074836153 |
66643 |
0.00952598689224 |
66644 |
0.0160751028807 |
66652 |
0.00119074836153 |
66653 |
0.00952598689224 |
66654 |
0.0321502057613 |
66655 |
0.038103947569 |
66662 |
0.000297687090383 |
66663 |
0.00238149672306 |
66664 |
0.00803755144033 |
66665 |
0.0190519737845 |
66666 |
0.00744217725956 |
Of course, if you're only interested in some specific property of the results (like the number of kept dice, or the value of the highest kept die), you don't have to go through this whole table adding up the probabilities. Instead, just modify the AnyDice code to return that property directly (e.g. with result: #KEEP
or result: 1@KEEP
) and re-run it.