Paste: Simplify sequences of shuffle words.
Author: | pozorvlak |
Mode: | factor |
Date: | Sun, 29 Nov 2009 19:47:09 |
Plain Text |
USING: combinators.smart kernel quotations sequences sequences.product
math.ranges assocs arrays ;
IN: tools.shuffle-simplify
: id ( -- ) ;
: shuffles ( -- seq )
{
drop 2drop 3drop nip 2nip
dup 2dup 3dup dupd over 2over pick tuck
swap swapd rot -rot spin roll -roll
} ;
: shuffles-id ( -- seq ) { id } shuffles append ;
: behaviour ( quot -- seq )
10 [0,b] prepend >quotation output>array ; inline
: shuffle-behaviours ( -- assoc )
shuffles-id [ [ 1quotation behaviour ] keep ] H{ } map>assoc ; inline
: simplify ( seq -- seq )
>quotation behaviour shuffle-behaviours at ; inline
: simplify-all ( n -- seq )
shuffles <repetition> <product-sequence>
[ dup simplify ] H{ } map>assoc [ nip ] assoc-filter ; inline
Author: | pozorvlak |
Mode: | factor |
Date: | Sun, 29 Nov 2009 22:29:54 |
Plain Text |
USING: combinators.smart kernel quotations sequences sequences.product
math.ranges assocs arrays ;
IN: tools.shuffle-simplify
: id ( -- ) ;
: shuffles ( -- seq )
{
drop 2drop 3drop nip 2nip
dup 2dup 3dup dupd over 2over pick tuck
swap swapd rot -rot spin roll -roll
} ;
: shuffles-id ( -- seq ) { id } shuffles append ;
: behaviour ( seq -- seq )
10 [0,b] prepend >quotation output>array ; inline
: shuffle-behaviours ( -- assoc )
shuffles-id [ [ 1quotation behaviour ] keep ] H{ } map>assoc ; inline
: simplify ( seq -- seq )
behaviour shuffle-behaviours at ; inline
: simplify-all ( n -- seq )
shuffles <repetition> <product-sequence>
[ dup simplify ] H{ } map>assoc [ nip ] assoc-filter ; inline
New Annotation