I have a List<List<T>>
the length of both list dimensions varies.
Using recursion I can calculate all the combinations
Some example List<List<T>>
and their combinations
[
[1],
[2, 3],
[4, 5, 6]
]
// [1, 2, 4], [1, 2, 5], [1, 2, 6], [1, 3, 4], [1, 3, 5], [1, 3, 6]
[
[0, 4],
[3, 4, 1, 2]
]
// [0, 3], [0, 4], [0, 1], [0, 2], [4, 3], [4, 4], [4, 1], [4, 2]
[
["A", "B", "B"],
["C"]
]
// ["A", "C"], ["B", "C"], ["B, "C"]
The amount of combinations can grow rapidly and using recursion becomes a memory and performance issue.
How can I implement an iterator to iterate through the combinations as they are calculated?
Doing some reading I might be able to use a factorial or combinatorial number system, but im not sure how I would apply it in this situation.