Suppose you have dice each with 4, 6, 8, and again 8 sides, and you roll them.
What are the odds of the result being 2 4 5 7?
The number 7 must come from an 8-sided die, 5 must come from a 6 or 8-sided die, and 2 may come from any of the given dice.
"Bruteforcing" this is kind of easy, here are all the possibilities:
4 6 8 8 : sided of the correspoding die
2 4 5 7
4 2 5 7
2 5 4 7
4 5 2 7
2 4 7 5
4 2 7 5
2 5 7 4
4 5 7 2
The answer is 8, (or should be, I did this on paper and it could be wrong).
If the roll is 1 5 8 8 then there is only 1 possible outcome, both the 8 sided dice are an 8, the 6 sided die is 5, and the last is 1.
What is the number of possible outcomes in a generic case? Is there a neat formula I could use?
I need all this because I want to optimize a script I'm writing, as currently it does not scale well with many dice. The number of dice and faces of each die are parameters to a function. It may be 10 20-sided dice or even a single hypotetic 1-sided die. What I need is a solution or formula that also considers the fact that a number could come from a subset of the dice. (copy and pasted from below)
It's possible to compute the solution without an exponential-time enumeration of all possible dice rolls. We can do this by iterating through the possible numbers from highest to lowest (in this case, 8, 7, 6, 5, 4, 3, 2, 1), and computing the distribution of how many dice rolled that number using the binomial distribution. Then we can put a state transition function on top of that based on the rules of the game, in this case seeing whether the pool rolled the required amount of that outcome. Here's a fuller explanation of the algorithm.
I implemented this approach as part of my hdroller Python library. You can try this computation in your browser using this JupyterLite notebook.
Denominator: 1536
So 8 is correct in this case.