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

    As graff pointed out, algorithmically, there is no way to predict how big a window would be required.

    Thanks for the input.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.