Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

combination

10 views
Skip to first unread message

sn0...@yahoo.com

unread,
Sep 23, 1999, 3:00:00 AM9/23/99
to
hi,

is there a module and doc for combination? if so, would you tell me
where i can get them?

i'm trying to get the most possible combination of elements from 3
arrays (not equal in size).

@one = qw(blue green yellow)
@two = qw(john nancy)
@three = qw(north south east west)

no repeat and order matters.

i am open for any (intellectual) suggestion if there is another away
of doing this.

tia,
r-e

another perl newbie


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

Greg Bacon

unread,
Sep 23, 1999, 3:00:00 AM9/23/99
to
In article <7sdr1n$ibn$1...@nnrp1.deja.com>,
sn0...@yahoo.com writes:

: i'm trying to get the most possible combination of elements from 3


: arrays (not equal in size).
:
: @one = qw(blue green yellow)
: @two = qw(john nancy)
: @three = qw(north south east west)
:
: no repeat and order matters.

my @combs;

foreach my $a (@one) {
foreach my $b (@two) {
foreach my $c (@three) {
push @combs, [$a, $b, $c];
}
}
}

If you wanted, you could take the resulting @combs and compute all
possible permutations of those too.

Greg
--
Must one first batter their ears, that they may learn to hear with
their eyes? Must one clatter like kettledrums and penitential
preachers? Or do they only believe the stammerer?
-- Nietzsche

Samuel Kilchenmann

unread,
Sep 24, 1999, 3:00:00 AM9/24/99
to
<sn0...@yahoo.com> wrote in: news:7sdr1n$ibn$1...@nnrp1.deja.com

>
> i'm trying to get the most possible combination of elements from 3
> arrays (not equal in size).
>
> @one = qw(blue green yellow)
> @two = qw(john nancy)
> @three = qw(north south east west)
>
> no repeat and order matters.
>
> i am open for any (intellectual) suggestion if there is another away
> of doing this.
>
A little "intellectual" challenge for you (derived from one of Abigail's
jewels):

my @out = ("");
foreach ([@three], [@two], [@one]) {
@out = map {my $new = $_; map {length () ? "$new, $_" : $new} @out}
@$_;
}
$" = "\n"; print "@out\n";


0 new messages