Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a 2D array storing the possible words at each position in a string. So, for example:

the
cat dog
sat lay
on
the
mat

(The first word must be `the', the second can be `cat' or `dog', etc).

I know there are 4 possible combinations but what is the most efficient way to extract these combinations from the 2D array in Perl?

Thanks

Replies are listed 'Best First'.
Re: Combinatorial Algorithms
by shotgunefx (Parson) on Mar 06, 2002 at 12:17 UTC
    These a very handy snippet here posted by merlyn

    -Lee

    "To be civilized is to deny one's nature."
      Thanks. With a few modifications, the permutations code on there will do exactly what I want. AJK
        No prob. Thanks to merlyn for posting it. It saved me a lot if time one night and quicky made it on to my Personal Nodlet.

        -Lee

        "To be civilized is to deny one's nature."