I'm writing a function that helps me calculate the possible outcomes of summing a variable numbe of die with a variable number of sides (for instance, the total sum of two six-sided die and a four sided die) and I've been stumped for a while.
Rolling two three sided die for instance should output an array with all 9 possible combinations:
[[1,1],
[1,2],
[1,3],
[2,1],
(etc.)
[3,2],
[3,3]]
And I can't quite figure it out. I've managed to generate range to enumerate on, but I can't quite make it.
dice = [6,6]
diceRanges = [range(0, die) for die in dice]
diceIndex = [0 for die in dice]
outcomes = []
for idx, rng in enumerate(diceRanges):
for var in rng:
diceIndex[idx] = var
outcomes.append([val for val in diceIndex])
outcomes
I've seen some things around but never quite as simple as it seems to be.
Cheers