RE: fixed list combinatorics



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

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

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

combinations( \@list, \@comb );

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:andrew.curry@xxxxxxxxxxxx]
Sent: 28 November 2007 15:43
To: Dan Klose; beginners@xxxxxxxx
Subject: 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.





--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
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.




.



Relevant Pages

  • RE: fixed list combinatorics
    ... sub combinations { ... Subject: fixed list combinatorics ... 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)
  • Wrapping FileSystemWatcher to prevent crossthread ops
    ... Public Shadows Event Changed(ByVal sender As Object, ... Private Delegate Sub DelegatorFSE(ByVal sender As Object, ... Private Sub watch_Changed(ByVal sender As Object, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Global.asax not firing
    ... Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) ... ' Fires when the application is started ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Global.asax not firing
    ... Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) ... ' Fires when the application is started ...
    (microsoft.public.dotnet.framework.aspnet)

Loading