Re: fixed list combinatorics
- From: perlmunky@xxxxxxxxxxxxxx (Dan Klose)
- Date: Wed, 28 Nov 2007 16:01:57 +0000
Thanks for your help.
On Nov 28, 2007 3:51 PM, Andrew Curry <andrew.curry@xxxxxxxxxxxx> wrote:
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.
- References:
- RE: fixed list combinatorics
- From: Andrew Curry
- RE: fixed list combinatorics
- Prev by Date: Comparing Regular Expression in Perl vs Python
- Next by Date: How to add commas to a number?
- Previous by thread: RE: fixed list combinatorics
- Next by thread: Time Comparison Easier Than I'm Making them
- Index(es):
Relevant Pages
|
|