Skip to main content
Added variant solutions
Source Link
ammut
  • 4.8k
  • 6
  • 29
  • 42

In programming, there are often as many correct ways to solve a problem, as there are programmers. Sometimes even more. The best way to learn a tool is to read code, so here are three ways of solving your problem, showcasing the possibilities of anydice.

Variant 1

When trying to inspect the all results of a die roll separately in anydice, it's often easiest to do so in a function which takes a number as a parameter, and pass it the die roll as an argument. So:

function: successes EIGHT:n { ... } output [successes 1d8] 

Next, it's only a matter of checking for favorable cases and keeping count:

SUCCESSES: 0 if EIGHT >= 6 { SUCCESSES: SUCCESSES + 1 } if EIGHT >= 8 { SUCCESSES: SUCCESSES + 1 } 

If we put it all together, it might look like this:

function: successes A:n B:n C:n EIGHT:n { S: 0 if EIGHT >= 6 { S: S + 1 } if EIGHT >= 8 { S: S + 1 } if A >= 5 { S: S + 1 } if B >= 5 { S: S + 1 } if C >= 5 { S: S + 1 } result: S } output [successes 1d6 1d6 1d6 1d8] 

Now if we calculate the result and click "At Least", we can see that the probability of at least two successes is 46.3%.

Variant 2

Another option is to simply construct a die that rolls the number of successes with their respective probabilities:

EIGHT: {} loop N over {1d8} { if N >= 8 { EIGHT: { EIGHT , 2 } } else if N >= 6 { EIGHT: { EIGHT , 1 } } else { EIGHT: { EIGHT , 0 } } } SIX: {} loop N over {1d6} { if N >= 5 { SIX: { SIX, 1 } } else { SIX: { SIX, 0 } } } output 3dSIX + 1dEIGHT 

We can then make us of the "At Least" visualization again to arrive at the same result.

Variant 3

Inspired by Variant 2, given that the "successes" die is pretty easy to construct ourselves, we could also just write:

EIGHT: { 0, 0, 0, 0, 0, 1, 1, 2 } SIX: { 0, 0, 0, 0, 1, 1 } output 3dSIX + 1dEIGHT 

When trying to inspect the all results of a die roll separately in anydice, it's often easiest to do so in a function which takes a number as a parameter, and pass it the die roll as an argument. So:

function: successes EIGHT:n { ... } output [successes 1d8] 

Next, it's only a matter of checking for favorable cases and keeping count:

SUCCESSES: 0 if EIGHT >= 6 { SUCCESSES: SUCCESSES + 1 } if EIGHT >= 8 { SUCCESSES: SUCCESSES + 1 } 

If we put it all together, it might look like this:

function: successes A:n B:n C:n EIGHT:n { S: 0 if EIGHT >= 6 { S: S + 1 } if EIGHT >= 8 { S: S + 1 } if A >= 5 { S: S + 1 } if B >= 5 { S: S + 1 } if C >= 5 { S: S + 1 } result: S } output [successes 1d6 1d6 1d6 1d8] 

Now if we calculate the result and click "At Least", we can see that the probability of at least two successes is 46.3%.

In programming, there are often as many correct ways to solve a problem, as there are programmers. Sometimes even more. The best way to learn a tool is to read code, so here are three ways of solving your problem, showcasing the possibilities of anydice.

Variant 1

When trying to inspect the all results of a die roll separately in anydice, it's often easiest to do so in a function which takes a number as a parameter, and pass it the die roll as an argument. So:

function: successes EIGHT:n { ... } output [successes 1d8] 

Next, it's only a matter of checking for favorable cases and keeping count:

SUCCESSES: 0 if EIGHT >= 6 { SUCCESSES: SUCCESSES + 1 } if EIGHT >= 8 { SUCCESSES: SUCCESSES + 1 } 

If we put it all together, it might look like this:

function: successes A:n B:n C:n EIGHT:n { S: 0 if EIGHT >= 6 { S: S + 1 } if EIGHT >= 8 { S: S + 1 } if A >= 5 { S: S + 1 } if B >= 5 { S: S + 1 } if C >= 5 { S: S + 1 } result: S } output [successes 1d6 1d6 1d6 1d8] 

Now if we calculate the result and click "At Least", we can see that the probability of at least two successes is 46.3%.

Variant 2

Another option is to simply construct a die that rolls the number of successes with their respective probabilities:

EIGHT: {} loop N over {1d8} { if N >= 8 { EIGHT: { EIGHT , 2 } } else if N >= 6 { EIGHT: { EIGHT , 1 } } else { EIGHT: { EIGHT , 0 } } } SIX: {} loop N over {1d6} { if N >= 5 { SIX: { SIX, 1 } } else { SIX: { SIX, 0 } } } output 3dSIX + 1dEIGHT 

We can then make us of the "At Least" visualization again to arrive at the same result.

Variant 3

Inspired by Variant 2, given that the "successes" die is pretty easy to construct ourselves, we could also just write:

EIGHT: { 0, 0, 0, 0, 0, 1, 1, 2 } SIX: { 0, 0, 0, 0, 1, 1 } output 3dSIX + 1dEIGHT 
Source Link
ammut
  • 4.8k
  • 6
  • 29
  • 42

When trying to inspect the all results of a die roll separately in anydice, it's often easiest to do so in a function which takes a number as a parameter, and pass it the die roll as an argument. So:

function: successes EIGHT:n { ... } output [successes 1d8] 

Next, it's only a matter of checking for favorable cases and keeping count:

SUCCESSES: 0 if EIGHT >= 6 { SUCCESSES: SUCCESSES + 1 } if EIGHT >= 8 { SUCCESSES: SUCCESSES + 1 } 

If we put it all together, it might look like this:

function: successes A:n B:n C:n EIGHT:n { S: 0 if EIGHT >= 6 { S: S + 1 } if EIGHT >= 8 { S: S + 1 } if A >= 5 { S: S + 1 } if B >= 5 { S: S + 1 } if C >= 5 { S: S + 1 } result: S } output [successes 1d6 1d6 1d6 1d8] 

Now if we calculate the result and click "At Least", we can see that the probability of at least two successes is 46.3%.