in reply to Subsets and adjacent values
It would be far better to just produce the sets you want than to produce more than you want and then throw some away. The sets you are after are quite easily produced iteratively with a couple of loops:
After the fog cleared:
#! perl -slw use strict; sub adjSets{ my $min = shift; map { my $start = $_; map { [ @_[ $start .. $start+$_ ] ] } $min-1 .. $#_-$start; } 0 .. $#_ - $min; } sub adjSets2{ my $min = shift; my @rv; for my $start ( 0 .. $#_ - $min ) { for my $len ( $min-1 .. $#_-$start ) { push @rv, [ @_[ $start .. $start+$len ] ]; } } return @rv; } print "@$_" for adjSets( 2, 'A'..'E' );; __END__ c:\test>689189 A B A B C A B C D A B C D E B C B C D B C D E C D C D E
Update: Ignore below. T'was too early in my day, so just downvote this. Comments unnecessary :)
Early morning brainfart
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Subsets and adjacent values
by andreas1234567 (Vicar) on Jun 02, 2008 at 09:14 UTC | |
by BrowserUk (Patriarch) on Jun 02, 2008 at 11:05 UTC |