gpm1982 has asked for the wisdom of the Perl Monks concerning the following question:
hello there.
i need some help here. what im trying to do is to list out combinations of a given array of strings, numbers, etc.
for example:
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
i need some help here. what im trying to do is to list out combinations of a given array of strings, numbers, etc.
for example:
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: generate combinations of lists
by ikegami (Patriarch) on Sep 28, 2005 at 06:07 UTC | |
Re: generate combinations of lists
by gargle (Chaplain) on Sep 28, 2005 at 07:27 UTC | |
| |
Re: generate combinations of lists
by planetscape (Chancellor) on Sep 28, 2005 at 05:13 UTC | |
Re: generate combinations of lists
by kprasanna_79 (Hermit) on Sep 28, 2005 at 07:16 UTC | |
Re: generate combinations of lists
by Skeeve (Parson) on Sep 28, 2005 at 07:19 UTC |
Back to
Seekers of Perl Wisdom