I'm way too tired now to try this and would like to ask you for help. Not to implement - I'll try tomorrow again - but preferably some pointers. I'm sure this has been done before:
I need a subroutine that is given an arbitrary number of lists and returns the cartesian product of these lists - preserving the ordering. e.g.
# comb([qw(a b c)],[qw(1 2 3)],[qw(- + *)]); # -> [[a,1,-],[a,1,+],[a,1,*], # [a,2,-],[a,2,+],[a,2,*], # [a,3,-],[a,3,+],[a,3,*], # [b,1,-],[b,1,+],[b,1,*], # [b,2,-],[b,2,+],[b,2,*], # [b,3,-],[b,3,+],[b,3,*], # [c,1,-],[c,1,+],[c,1,*], # [c,2,-],[c,2,+],[c,2,*], # [c,3,-],[c,3,+],[c,3,*]] #
You get the idea. The problem for me is, that the number of lists given is variable and I simply don't get the required iteration/recursion to achieve that combinatorics.
Many thanks for any pointers.
Punymonk
In reply to cartesian product preserving order by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |