EDIT
Just found another thread on SO that's pretty much exactly what I needed: How can I create cartesian product of vector of vectors?
Thanks everyone!
Let's say I have one set of values S1(A, B, C)
and another, S2(D, E, F)
, where a transformation S1 -> S2
will give another set, S3
, where S3(AD, AE, AF, BD, BE, BF, CD, CE, CF)
; in other words, I'd like to map each value of the first set to each value of the second set, thus getting a third set that has a size of S1 x S1
.
Now, doing this for two sets is a trivial matter, however, I am at a loss when it comes to have a variable number of sets, i.e. S1 -> S2 -> S3 -> ... -> Sn
If we view this as a tree/graph structure, the problem is solved by finding every single path:
start
.
. . .
A B C
. . .
. . . . . . . . .
D E F D E F D E F
Is there a scalable algorithm to solve this problem?