2
\$\begingroup\$

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.

\$\endgroup\$

1 Answer 1

6
\$\begingroup\$

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]
\$\endgroup\$
2
  • 2
    \$\begingroup\$ 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). \$\endgroup\$
    – Carcer
    Apr 23, 2020 at 11:52
  • \$\begingroup\$ @Carcer Derp, well that simplifies some things for me \$\endgroup\$
    – Someone_Evil
    Apr 23, 2020 at 12:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .