RosettaCodeData/Task/Non-continuous-subsequences/Perl/non-continuous-subsequences.pl

19 lines
553 B
Perl
Raw Permalink Normal View History

2013-04-10 23:57:08 -07:00
my ($max, @current);
sub non_continuous {
2019-09-12 10:33:56 -07:00
my ($idx, $has_gap) = @_;
my $found;
2013-04-10 23:57:08 -07:00
for ($idx .. $max) {
push @current, $_;
# print "@current\n" if $has_gap; # uncomment for huge output
$found ++ if $has_gap;
$found += non_continuous($_ + 1, $has_gap) if $_ < $max;
pop @current;
$has_gap = @current; # don't set gap flag if it's empty still
}
$found;
}
2019-09-12 10:33:56 -07:00
$max = 20;
2013-04-10 23:57:08 -07:00
print "found ", non_continuous(1), " sequences\n";