After much experimentation, puzzlement by the way Anydice handles types, and contacting Catlike Coding for help, here's a piece of code that does account for Exploding Dice and Glitches.
How to Use
Just open the link, adjust the number of DICE in your pool, and optionally adjust MAXDEPTH.
The MAXDEPTH variable sets how many recursions of exploding dice are processed. For pools around 13-20 dice, depth shouldn't exceed 2 (and precision doesn't matter as much). For smaller pools you can increase it.
How to Interpret the Results
Positive results mean the listed numbers of success without a Glitch1.
Negative results mean the listed number of hits, but with a Glitch.
*Exception: -999** means a Critical Glitch occurred (ones but no hits).
Why the Code's So Complicated
Anydice is geared towards operating on probabilities more than on normal numbers; e.g., there are various places where it expects to receive unrolled dice pools instead of numbers, and workarounds have to be implemented (such as the mysterious-looking override of the explode function). On the bright side, the workarounds were written by Jasper Flick himself.
Likewise, Anydice isn't geared towards splitting a single roll into multiple outputs, thus the hack with using negative values and the special meaning of -999.
Whole Code
In case Anydice is down and you want to read this for reference, or don't want to click the link.
DICE: 13
MAXDEPTH: 2
\Calculate successes for Shadowrun, with Glitch probabilities (ones*2 > hits)\
\A result of -999 means a Critical Glitch (0 hits)\
\Negative results mean X hits but with a Glitch\
\Positive results are numbers of hits\
\MAXDEPTH is how many recursions of Exploding Dice are allowed\
\With high pools, use lower depth (loss of precision, but less risk of timing out)\
\With low pools, you can increase the depth\
\All hail Catlike Coding!\
function: explode N:n plus X {
if N = 6 { result: [explode d6 plus X + 1] }
if N = 5 { result: X + 1 }
if N = 1 {
if X { result: -X }
result: -100
}
result: X
}
function: parse ROLL:s {
ONES: 0
HITS: 0
loop N over ROLL {
if N > 0 { HITS: HITS + N }
else if N = -100 { ONES: ONES + 1 }
else if N HITS {
if HITS { result: -HITS }
result: -999
}
result: HITS
}
set "maximum function depth" to MAXDEPTH
D: [explode d6 plus 0]
output [parse DICEdD]
1 Using the
'ones > hits/2' definition of a Glitch. If you play with a different definition, feel free to change the > to a >= in the code.