I am working on a dice pool system for skills and actions to be used in a new system.

In this system, any rolls of 1 will negatively affect the outcome of resolving an action using a dice pool.

In this instance, I am trying to model the probability of each outcome when rolling 2d4 with 1d4 disadvantage/adversity by looking at the total of the 2 highest dice rolled (which in this case is the entire 2d4) after disadvantage is calculated.

The way disadvantage is intended to work is:

- Any disadvantage dice that roll a 1 are added to the pool
- Any disadvantage dice that roll above 1 will remove the highest die in the pool of equal or lesser value from the pool if that die in question is greater than 1 (the disadvantage die itself is not added)

Since it is not possible to remove elements from sequences, I am trying to build up the sequence DISADVANTAGEPROCESSED while excluding dice that would be removed from the pool so the function can then return the total of the requested number of dice specified in the parameter POSTOOUTPUT calculated from this sequence.

I have worked on code similar to the below for several days and while I have advantage (and passing the dice sequence straight through with no advantage or disadvantage) working, I am still not getting what I believe are the correct results that I have done by manually mapping out the 64 possible outcomes.

The mechanics of adding disadvantage dice that roll 1 to the pool seem to be working, as I have determined by running the code with POSSTOOUTPUT set to {3}.

I have a feeling that I am missing something obvious and will still keep working on it, but any insight or guidance that can be offered would be much appreciated.

```
LOWMAX: 1
DICESEQ: 2d4
ADVANTAGESEQ: {}
DISADVANTAGESEQ: 1d4
POSTOOUTPUT: {1..2}
function: POSITION:s DICEPARAM:s with ADVANTAGEPARAM:s advantage and DISADVANTAGEPARAM:s disadvantage
{
ADVANTAGE: 0
ADVANTAGEPROCESSED: {}
DISADVANTAGEPROCESSED: {}
Other code omitted due to irrelevance
if DISADVANTAGEPARAM != {} & ADVANTAGEPARAM = {} If there is only disadvantage
{
loop Y over {1..#DISADVANTAGEPARAM} Have also tried loop Y over DISADVANTAGEPARAM and not used the indexing
{
REMOVED: 0 This flag is to be set when a die has been removed from the pool for the current disadvantage die in the sequence
loop X over {1..#DICEPARAM} Have also tried loop X over DICEPARAM, no different
{
Have also tried without the whole loops and just gone with code like if DICEPARAM > DISADVANTAGEPARAM hoping that the mechanics of passing dice collections to the function as parameters that expect sequences will do the job, still no luck
if X@DICEPARAM>Y@DISADVANTAGEPARAM | X@DICEPARAM <=LOWMAX
{
DISADVANTAGEPROCESSED: {DISADVANTAGEPROCESSED, X@DICEPARAM}
}
if X@DICEPARAM <= Y@DISADVANTAGEPARAM
{
if !REMOVED
{
REMOVED: 1
}
else
{
DISADVANTAGEPROCESSED: {DISADVANTAGEPROCESSED, X@DICEPARAM}
}
}
if Y@DISADVANTAGEPARAM <= LOWMAX
{
DISADVANTAGEPROCESSED: {DISADVANTAGEPROCESSED, Y@DISADVANTAGEPARAM}
}
}
}
COMBINED: (sort {DISADVANTAGEPROCESSED})
result: POSITION@COMBINED
}
}
output (POSTOOUTPUT DICESEQ with ADVANTAGESEQ advantage and DISADVANTAGESEQ disadvantage) named "(DICESEQ) with (ADVANTAGESEQ) advantage and (DISADVANTAGESEQ) disadvantage"
```
```