rendered paste bodysub FilterSeries {
my( $base, $generations, @series ) = @_;
my @newseries;
my ( $next, $i, $j );
for( $i = 1; $i < $generations; $i++) {
if( $i <= $base ) {
$next = $i;
}
else {
$j = $i - $base;
$next = $base + ($j * $j);
}
#print "Nextval: $next\n";
my @candidates;
my $keeper;
# Candidates for "next" backup are everything <= the next value
while( @series && $series[0] <= $next ) {
push( @candidates, shift( @series ));
}
if( @candidates ) {
# Keep oldest one only
$keeper = pop( @candidates );
#print "Keep $keeper\n";
# Delete the rest
foreach my $cand ( @candidates ) {
print "Delete $cand\n";
}
push( @newseries, $keeper );
}
}
# Delete any leftover entries older than the max
foreach my $cand ( @series ) {
print "Delete off end: $cand\n";
}
return @newseries;
}