Re: fixed list combinatorics
- From: krahnj@xxxxxxxxx (John W . Krahn)
- Date: Wed, 28 Nov 2007 17:12:26 -0800
On Wednesday 28 November 2007 06:32, Dan Klose wrote:
Hi list,
Hello,
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.
Another way to do it:
$ perl -le'
my $list = join "", 1 .. 4;
for my $len ( 1 .. length $list ) {
for my $elem ( 0 .. length( $list ) - 1 ) {
my $out = substr $list, $elem, $len;
print $out if $len == length $out;
}
}
'
1
2
3
4
12
23
34
123
234
1234
John
--
use Perl;
program
fulfillment
.
- References:
- fixed list combinatorics
- From: Dan Klose
- fixed list combinatorics
- Prev by Date: Re: Perl upgrade @INC help
- Next by Date: Re: Perl upgrade @INC help
- Previous by thread: Re: fixed list combinatorics
- Next by thread: RE: fixed list combinatorics
- Index(es):
Relevant Pages
|