Odds of rolling 3 or more consecutive numbers on n number of dice

189 Views Asked by At

I'm searching for an answer to the above problem - how to calculate the probability of getting 3 or more sequential numbers on n number of dice.

I found this formula for 6 six-sided dice here (What are the odds of rolling a 3 number straight throwing 6d6) :

$$ 6^n - 6\cdot4^n + 8\cdot3^n - 3\cdot 2^n \over 6^n $$ However, I can't wrap my head around how to convert this if the die type were changed from d6 to d4s, d8s, or d10s.

Any help would be massively appreciated! Thanking you kindly for taking the time to read this.

1

There are 1 best solutions below

6
On BEST ANSWER

Icepool

My Icepool Python package can do this computation:

from icepool import d4, d6, d8, d10, d12, Pool
output(Pool([d6, d6, d6, d6, d6, d6]).largest_straight())

You can try it online here.

You can even mix standard die types if you wish. The algorithm is based on representing the evaluation of the roll (in this case, finding the largest straight) as a series of state transitions over the (outcome, count) pairs resulting from the roll of the pool:

def next_state(state, outcome, count):
    best_run, run = state or (0, 0)
    if count >= 1:
        run += 1
    else:
        run = 0
    return max(best_run, run), run

and then using the decomposition of the multinomial as a product of binomials and dynamic programming to find the distribution efficiently. If you are curious to learn more, you can read my paper here.

@inproceedings{liu2022icepool,
    title={Icepool: Efficient Computation of Dice Pool Probabilities},
    author={Albert Julius Liu},
    booktitle={Eighteenth AAAI Conference on Artificial Intelligence and Interactive Digital Entertainment},
    volume={18},
    number={1},
    pages={258-265},
    year={2022},
    month={Oct.},
    eventdate={2022-10-24/2022-10-28},
    venue={Pomona, California},
    url={https://ojs.aaai.org/index.php/AIIDE/article/view/21971},
    doi={10.1609/aiide.v18i1.21971}
}

More examples

You can find the largest count of any outcome, aka largest matching set, aka best X-of-a-kind, by using largest_count():

Pool([d4, d4, d6, d6]).largest_count()

You can only consider dice that rolled certain outcomes by inserting keep_outcomes() or drop_outcomes(), which accept either a function or a collection of outcomes. You can put any evaluation (largest_count(), largest_straight(), etc.) that you want at the end. For example, these drop all 1-5s from the pool:

Pool([d6, d6, d8, d8]).keep_outcomes(lambda x: x >= 6).largest_count()
# equivalently:
Pool([d6, d6, d8, d8]).drop_outcomes([1, 2, 3, 4, 5]).largest_count()

If you want to only filter some of the dice, you can combine multiple pools using the + operator. For example, this combines a pool of 2d6 where only 6s are kept with a pool of 3d8 where everything is kept:

# d6.pool(2) is the same as Pool([d6, d6]).
(d6.pool(2).keep_outcomes([6]) + d8.pool(3)).largest_count()