|P is for Practical|
generate combinations of listsby gpm1982 (Initiate)
|on Sep 28, 2005 at 05:04 UTC||Need Help??|
gpm1982 has asked for the
wisdom of the Perl Monks concerning the following question:
i need some help here. what im trying to do is to list out combinations of a given array of strings, numbers, etc.
if i had an array like qw(a b c), i would like to generate combinations of the array above, so that i would have:
qw(a b c), qw(a c b), qw(b a c), qw(b c a), qw(c a b), and qw(c b a)
is there a way, in Perl, to come up with the result above? please help. thanx.
ps: to find out how many different combinations can be produced from an array of n elements, use factorial (!). for example, if i had an array of 5 elements, my combinations will have a total of
5! = 5x4x3x2x1 = 120 different combinations