The problem is based on the Shadowrun dice pool. There if half or more of your dice are a 1 you "glitch" which is a bit more than just failing the test. Successes are counted on number of 5+'s in your pool. If you glitch but don't have any successes it's a critical glitch. So this is basically about the probability of getting a critical glitch.
Well, here's a quick AnyDice script to calculate the odds of that:
function: glitch ROLL:s {
result: 2*[count 1 in ROLL] >= #ROLL & [count {5,6} in ROLL] = 0
}
output [glitch 7d6]
The way this works is that:
- The function
glitch ROLL:s
expects a sequence of numbers as a parameter. (That's what the :s
in the definition means.) When given a dice pool like 7d6
, AnyDice automatically calls the function for every possible (sorted) sequence of numbers obtainable by rolling the dice, and sums up the results into a single biased die representing the probability of the function returning each of the possible results when called with a random dice roll.
- In the function,
2*[count 1 in ROLL] >= #ROLL
evaluates to true (1) if at least half the numbers in the sequence ROLL
are ones, and to false (0) otherwise. Similarly, [count {5,6} in ROLL] = 0
evaluates to true if there are no fives or sixes in ROLL
, and to false otherwise. The operator &
between them is logical AND: it returns true (i.e. 1) only if both of the expressions around it are non-zero (i.e. not false).
So basically, there's no particularly fancy math here — AnyDice just solves the problem by brute force, testing every possible dice roll to see if it's a critical glitch or not. (There's a little bit of fancy math involved in calculating the probabilities of each sorted outcome of a 7d6 roll, but that all happens automatically behind the scenes.)
Ps. If you'd like to do this in Python instead, you could use e.g. the dice_pool
function from this answer, which does the same thing that AnyDice does internally — it generates all possible sorted rolls of an NdX pool and their respective probabilities. You could then just write a simple loop that sums up the probabilities of all the rolls that are critical glitches and outputs that.