Paste: two-or-less

Author: mrjbq7
Mode: factor
Date: Thu, 25 Apr 2013 20:50:18
Plain Text |
! removes sequences of characters that are repeated
! three or more times, keeping "two-or-less"...
: two-or-less ( seq -- seq' )
    dup dup '[
        dup 2 < [ 2drop t ] [
            [ 1 - _ nth = ] [ 2 - _ nth = ] 2bi and not
        ] if
     ] filter-index ;




IN: scratchpad "abcccccccdeefgg" two-or-less .
"abccdeefgg"

Annotation: two-or-less-newlines

Author: mrjbq7
Mode: factor
Date: Thu, 25 Apr 2013 20:57:15
Plain Text |
: two-or-less-newlines ( seq -- seq' )
    dup dup '[
        2dup [ CHAR: \n = ] [ 1 > ] bi* and [
            [ 1 - _ nth = ] [ 2 - _ nth = ] 2bi and not
        ] [ 2drop t ] if
    ] filter-index ;

New Annotation

Summary:
Author:
Mode:
Body: