in reply to How would you code this?
The pipe filter also uses reduce?
The idea that comes to my mind is a sliding window , like @ten, so before your program reduce
ahoy(\@points); sub ahoy { my( $points ) = @_; my @ten; for my $point ( @$points ){ push @ten, $point; if( @ten > 1 and $ten[-1][0] < $ten[-2][0] ){ ## back +ing up? ditch it splice @ten, -2; ## pop pop @ten; } if( @ten > 9 ){ print join ' ', @$_ for splice @ten, 0, 8 ; ## shift 8 } } print join ' ', @$_ for @ten; print '####'; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How would you code this?
by BrowserUk (Patriarch) on Apr 07, 2016 at 14:58 UTC |