Or a better one for none numeric's would be : I think.....

use strict;
my ( @list, @comb );

@list = ( 'A', 'B', 'C', 'D' );

combinations( [EMAIL PROTECTED], [EMAIL PROTECTED] );

print join ( "\n", @comb );

sub combinations {
    my ( $list, $comb ) = @_;
    my ( $key, $i, $x, $line, @comb, $n );
    $n = 1;
    foreach my $key ( @{$list} ) {
        $line = $key;
        push ( @{$comb}, $line );

        for ( my $i = $n ; $i <= $#list ; $i++ ) {
            $line .= $list->[$i];
            push ( @{$comb}, $line );
        }
        $n++;
    }
}

If this indeed what your asking.

A
AB
ABC
ABCD
B
BC
BCD
C
CD
D

-----Original Message-----
From: Andrew Curry [mailto:[EMAIL PROTECTED] 
Sent: 28 November 2007 15:43
To: Dan Klose; beginners@perl.org
Subject: RE: fixed list combinatorics

Not sure this exactly what you want but

use strict;
my ( @list, @comb );

@list = ( 1, 2, 3, 4 );

combinations( [EMAIL PROTECTED], [EMAIL PROTECTED] );

print join ( "\n", @comb );

sub combinations {
        my ( $list, $comb ) = @_;
        my ( $key, $i, $x, $line, @comb );

        foreach my $key ( @{$list} ) {
                $line = $key;
                push ( @{$comb}, $line );

                for ( my $i = $key ; $i <= $#list ; $i++ ) {
                        $line .= $list->[$i];
                        push ( @{$comb}, $line );
                }
        }
}

Runs and returns....

1
12
123
1234
2
23
234
3
34
4

-----Original Message-----
From: Dan Klose [mailto:[EMAIL PROTECTED] 
Sent: 28 November 2007 14:32
To: beginners@perl.org
Subject: fixed list combinatorics

Hi list,

I am having a bad day and would really like some help (the coffee hasn't).

I have a list that looks like:
my @list = (1,2,3,4);

I would like to generate all patterns that follow:
1
 2
 3
  4
12
123
 23
 34
 234
1234


The list can be of any length and the next number in the list must be the
current number +1 ( i am not working with numbers - i think it is easier to
explain this way).

How do I do this?  I did look at the Combinatorics module however it does
not impose fixed ordering as far as I can see.

Thanks


This e-mail is from the PA Group.  For more information, see
www.thepagroup.com.

This e-mail may contain confidential information.  Only the addressee is
permitted to read, copy, distribute or otherwise use this email or any
attachments.  If you have received it in error, please contact the sender
immediately.  Any opinion expressed in this e-mail is personal to the sender
and may not reflect the opinion of the PA Group.

Any e-mail reply to this address may be subject to interception or
monitoring for operational reasons or for lawful business practices.





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/



This e-mail is from the PA Group.  For more information, see
www.thepagroup.com.

This e-mail may contain confidential information.  Only the addressee is
permitted to read, copy, distribute or otherwise use this email or any
attachments.  If you have received it in error, please contact the sender
immediately.  Any opinion expressed in this e-mail is personal to the sender
and may not reflect the opinion of the PA Group.

Any e-mail reply to this address may be subject to interception or
monitoring for operational reasons or for lawful business practices.





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to