Paste: updown

Author: noam
Mode: factor
Date: Mon, 1 Nov 2010 22:27:46
Plain Text |
USING: kernel sequences grouping math.order make ;
IN: updown

! Removes adjacent equal element.
! Example: { 1 1 1 2 2 1 } -> { 1 2 1 }
: tighten ( seq -- seq )
    [ { } ]
    [
        [ 
            [ dup 2 <clumps> [ first2 = [ drop ] [ , ] if ] 2each ]
            [ last , ] bi 
        ] { } make
    ] if-empty ;


! Returns t if the sequence increases and then descends.
! Example: { 1 2 3 2 1 }
: updown? ( seq -- ? )
    2 <clumps> [ first2 <=> ] map tighten { +lt+ +gt+ } sequence= ;

New Annotation

Summary:
Author:
Mode:
Body: