# AnyDice: Sum of dice pool + highest value from the same roll

I want to calculate the sum of a mixed dice pool, but add the nth highest value of that pool twice.

For example the code

output 2d4+1@2d4


Gives the sum of 2d4 and the highest value of a separately rolled 2d4. Instead I'd like to add the highest value of the same 2d4.

This does produce different results; in the example above the probability of rolling a total of 3 is 0.39%, while in the situation I'm after the probability should be 6.25%.

Ideally the solution should be able to handle rolling mixed die pools such as 2d10+1d8+1d6+the second highest value rolled, but I would still find solutions that cannot do so useful.

# Functions and casting

In general, if you want to do things with a roll of a pool of dice, you'll want to use a function which takes in a sequence. That function will be evaluated for each possible roll, so your sequence in the function can be treated as a possible roll.

We then just need the highest (which will be first for a generated sequence) and to take its sum. Here nicely (thanks Carcer for reminding me) a sequence is converted to its sum when used as number, so we can just add the two together.

function: doublehighest POOL:s {
result: 1@POOL + POOL
}

output [doublehighest 2d6]

• I don't think you need a separate function to sum the sequence - as per the docs, "When mathematical or boolean operations are performed on a sequence, all its values are summed and the sequence behaves as if it were a single number." 1@POOL + POOL should work (and does, if I test it). – Carcer Apr 23 at 11:52
• @Carcer Derp, well that simplifies some things for me – Someone_Evil Apr 23 at 12:12