RE: fixed list combinatorics



Not sure this exactly what you want but

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

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

combinations( \@list, \@comb );

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:perlmunky@xxxxxxxxxxxxxx]
Sent: 28 November 2007 14:32
To: beginners@xxxxxxxx
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.




.



Relevant Pages

  • RE: fixed list combinatorics
    ... use strict; ... sub combinations { ... This e-mail may contain confidential information. ... Any opinion expressed in this e-mail is personal to the sender ...
    (perl.beginners)
  • Re: fixed list combinatorics
    ... sub combinations { ... Subject: fixed list combinatorics ... This e-mail may contain confidential information. ... If you have received it in error, please contact the sender ...
    (perl.beginners)
  • RE: Trying to figureout regex please help
    ... Trying to figureout regex please help ... Can contain a group of letters or numbers, ... This e-mail may contain confidential information. ... Any opinion expressed in this e-mail is personal to the sender ...
    (perl.beginners)
  • RE: Calling bash things inside perl script.
    ... To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx For additional ... commands, e-mail: beginners-help@xxxxxxxx http://learn.perl.org/ ... This e-mail may contain confidential information. ... Any opinion expressed in this e-mail is personal to the sender ...
    (perl.beginners)
  • RE: how to remove ^M character from every line
    ... also remove any formatting from the end of lines. ... interested in trailing whitespace characters. ... This e-mail may contain confidential information. ... Any opinion expressed in this e-mail is personal to the sender ...
    (perl.beginners)