Re: fixed list combinatorics
- From: rob.dixon@xxxxxxx (Rob Dixon)
- Date: Wed, 28 Nov 2007 17:59:16 +0000
Dan Klose wrote:
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.
Hi Dan
I feel there must be a neater way, but the sledgehammer technique gives
me the code below.
HTH,
Rob
use strict;
use warnings;
my @list = 1..4;
foreach my $start (0 .. $#list) {
foreach my $end ($start .. $#list) {
my @sublist = @list[$start..$end];
print join('', @sublist), "\n";
}
}
**OUTPUT**
1
12
123
1234
2
23
234
3
34
4
.
- References:
- fixed list combinatorics
- From: Dan Klose
- fixed list combinatorics
- Prev by Date: How to add commas to a number?
- Next by Date: Variable division, assignment and sprintf in one line
- Previous by thread: Re: fixed list combinatorics
- Next by thread: Re: fixed list combinatorics
- Index(es):
Relevant Pages
|
|