Given two integers n and m, generate all possible outcomes of rolling n dice, where each die has m faces numbered 1 through m.
Each outcome is a list of n values, where the i-th value is the face shown by the i-th die. Dice are distinguishable, so [1, 2] and [2, 1] are different outcomes.
Implement the solution recursively.
Function Signature
def dice_rolls(n: int, m: int) -> list[list[int]]:
Rules
-
Return every outcome exactly once, so the result has
m ** n
lists.
-
Return the outcomes in ascending lexicographic order: compare the first die's face, then the second die's face on a tie, and so on.
Constraints
Examples
Input: n = 2, m = 2
Output: [[1,1],[1,2],[2,1],[2,2]]
Each of the 2 dice can show 1 or 2, giving 2 * 2 = 4 outcomes. [1,2] and [2,1] both appear because the dice are distinguishable.
Input: n = 1, m = 3
Output: [[1],[2],[3]]
A single die with 3 faces has 3 outcomes.
Input: n = 3, m = 2
Output: [[1,1,1],[1,1,2],[1,2,1],[1,2,2],[2,1,1],[2,1,2],[2,2,1],[2,2,2]]
Three dice with 2 faces each give 2 * 2 * 2 = 8 outcomes. All outcomes that start with 1 come before those that start with 2, and the same rule orders the second and third positions.