Drawmack
First Post
My earlier algorithm was significantly flawed. Here is how the problem can be done recursivly.
Problem:
Calculate the probability of a given result coming up when rolling xdy.
Solution:
You have a set (A) of dice, each element of A is a set (B) of sides. So we need to calculate the set (C) such that C = all the elements of B such that they can be added to any total produced by summing one element from each set B in A such that the total (F) = our desired result (G)
Extremely Abstract Agorithm
1) Calculate the maximum from the current B that can be added to the minimum of all other Bs to equal G.
2) Calculate the minimum from the current B that can be added to the maximum of all other Bs to equal G.
3) Repeat with each B in A
There are a couple of points about working with dice that make this simpler. Namely we are only working with integers between 1 and n, where n is the number of side the die has. This being the case our minimum (min) is:
1 * number of dice (nd)
and our maximum (max) is:
sum(sides of all dice), except the current one (sd)
We can calculate the minimum roll possible on this die like so:
x = G-(max - current die)
if x < 1 then
x = 1
We can calculate the maximum roll possible on this die like so:
x = G-(min - 1)
if x < 1 then
result is impossible
the tricky part is putting this together recursivly to calculate all of the possible sets for a given number.
I believe this is the quickest way to make a computer handle it.
Problem:
Calculate the probability of a given result coming up when rolling xdy.
Solution:
You have a set (A) of dice, each element of A is a set (B) of sides. So we need to calculate the set (C) such that C = all the elements of B such that they can be added to any total produced by summing one element from each set B in A such that the total (F) = our desired result (G)
Extremely Abstract Agorithm
1) Calculate the maximum from the current B that can be added to the minimum of all other Bs to equal G.
2) Calculate the minimum from the current B that can be added to the maximum of all other Bs to equal G.
3) Repeat with each B in A
There are a couple of points about working with dice that make this simpler. Namely we are only working with integers between 1 and n, where n is the number of side the die has. This being the case our minimum (min) is:
1 * number of dice (nd)
and our maximum (max) is:
sum(sides of all dice), except the current one (sd)
We can calculate the minimum roll possible on this die like so:
x = G-(max - current die)
if x < 1 then
x = 1
We can calculate the maximum roll possible on this die like so:
x = G-(min - 1)
if x < 1 then
result is impossible
the tricky part is putting this together recursivly to calculate all of the possible sets for a given number.
I believe this is the quickest way to make a computer handle it.