8
\$\begingroup\$

Basically, I'm trying to do something like [highest 1 of {a pool of Xd4, Yd6, Zd8, etc, all together}]

For example:I roll 1d4 and 1d6 and 1d8; their results are, respectively, 4(out of 4 max), 5(out of 6) and 2(out of 8). My end result is 5 here.

How would I do such a thing in AnyDice syntax?

\$\endgroup\$
  • \$\begingroup\$ For "highest of 3d4, 2d6 and 1d8", if you roll (4, 4, 4), (5, 5) and (7), do you want a result of 7 (= highest individual die) or 12 (= highest sum of each kind of die)? Or, in other words, is there a difference between "highest of 1d6, 2d6 and 3d6" and "highest of 6d6"? \$\endgroup\$ – Ilmari Karonen Jun 17 '15 at 15:47
7
\$\begingroup\$

This is doable, but you'll need to break it up into smaller chunks, so the syntax will get a bit annoying. Here's an example:

output [highest of [highest of 1@2d4 and 1@4d6] and [highest of 1@5d8 and 1@2d10]]

Now to break this down: The highest of X and Y function grabs the higher value of the two supplied. The 1@2d4 syntax grabs the highest die rolled in the given pool.

  • [highest of 1@2d4 and 1@4d6] - The higher of the best d4 and the best d6
  • [highest of 1@5d8 and 1@2d10] - The higher of the best d8 and the best d10
  • [highest of [highest of 1@2d4 and 1@4d6] and [highest of 1@5d8 and 1@2d10]] - The higher of the result from the previous two.

You can also continue nesting higher of X and Y as much as you need to cover all the dice pools.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ This is the most fitting to what I'm trying to do and the easiest to understand, thank you! \$\endgroup\$ – Alex Mitan Jul 1 '15 at 9:30
6
\$\begingroup\$

I made the code in such a way that you only have to change X, Y and Z, and also so you have the function highest result of..., so you can use for further dice.

X:1
Y:1
Z:1

function: highest num of AA:n BB:n CC:n{
 if AA > BB {
  if AA > CC {result: AA}
  else {result: CC}
 }
 else {
  if BB > CC {result: BB}
  else {result: CC}
 }
}

function: highest result of A:s B:s C:s{
 result: [highest num of X@A Y@B Z@C]
}

output [highest result of Xd4 Yd6 Zd8]
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Definitely a more flexible answer than mine. \$\endgroup\$ – Bobson Jun 17 '15 at 14:26
  • \$\begingroup\$ I think this answer has a bug; to get correct results for X,Y,Z > 1, the output of the second function should be [highest num of 1@A 1@B 1@C] instead of [highest num of X@A Y@B Z@C]. (Also, I obviously think my own code is shorter and cleaner, but I may be biased there.) \$\endgroup\$ – Ilmari Karonen Jun 17 '15 at 16:46
  • \$\begingroup\$ Pretty sure there is a bug in the first if block. You say if AA > BB and AA > CC then AA is the highest, otherwise CC is. But AA > BB and BB > CC is still possible. \$\endgroup\$ – D.Spetz Jun 17 '15 at 19:16
  • 1
    \$\begingroup\$ If AA>BB and CC>AA, CC is the highest \$\endgroup\$ – Masclins Jun 17 '15 at 19:25
5
\$\begingroup\$

Assuming that you want to calculate the highest single die roll in the pool of mixed dice, here's one simple solution:

function: max A:n B:n C:n {
    result: 1@[sort {A, B, C}]
}
output [max 1@3d4 1@2d6 1@1d8]

This code is also easily extensible; for example, here's the same code with some d12s and a d20 thrown in:

function: max A:n B:n C:n D:n E:n {
    result: 1@[sort {A, B, C, D, E}]
}
output [max 1@5d4 1@4d6 1@3d8 1@2d12 1@1d20]

(Note how the results 13–20 all have a probability of 1/20 = 5% in this example: any time you roll above 12 on the single d20, that'll be the highest roll, regardless of what happens with the other dice. For the same reason, the probability of the highest roll being 7 or 8 is always 1/8 = 12.5% in the first example.)

The reason this code works is because the rule that "If a die is provided [to a function expecting a number], then the function will be invoked for all numbers on the die – or the sums of a collection of dice – and the result will be a new die." The built-in notation 1@DIE returns a (single, biased) die representing the distribution of the highest roll in the original die; the custom [max NUMBER NUMBER NUMBER], which just calculates the maximum of three numbers, is then called for each possible combination of maximum rolls, and the results weighed by the probability of the combinations. It's kind of a brute-force method, but it works.


Ps. If you write [max 3d4 2d6 1d8] instead of [max 1@3d4 1@2d6 1@1d8], you get something very different — namely, the maximum sum of each kind of dice. Basically, the 1@ causes the maximum of each of the three rolls to be passed to max, whereas leaving it out causes the sum each roll to be passed instead. Of course, if you have only one of each kind of die, then this makes no difference.

Also, for basically the same reason, the method described above cannot be easily adapted to give the second highest number in an irregular dice pool. To achieve that, you'll instead need to pass each sub-pool to the function as a sequence, as described here and here.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ This is clearly a more elegant approach. I tried to do something like what you did, but didn't managed to do so. \$\endgroup\$ – Masclins Jun 18 '15 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.