parent
635749a50b
commit
61c77e616f
|
@ -140,13 +140,13 @@ PRIVATE>
|
||||||
: strings ( alphabet length -- seqs )
|
: strings ( alphabet length -- seqs )
|
||||||
>r dup length r> number-strings map-alphabet ;
|
>r dup length r> number-strings map-alphabet ;
|
||||||
|
|
||||||
: nths ( nths seq -- subseq )
|
: switches ( seq1 seq -- subseq )
|
||||||
! nths is a sequence of ones and zeroes
|
! seq1 is a sequence of ones and zeroes
|
||||||
>r [ length ] keep [ nth 1 = ] curry subset r>
|
>r [ length ] keep [ nth 1 = ] curry subset r>
|
||||||
[ nth ] curry { } map-as ;
|
[ nth ] curry { } map-as ;
|
||||||
|
|
||||||
: power-set ( seq -- subsets )
|
: power-set ( seq -- subsets )
|
||||||
2 over length exact-number-strings swap [ nths ] curry map ;
|
2 over length exact-number-strings swap [ switches ] curry map ;
|
||||||
|
|
||||||
: push-either ( elt quot accum1 accum2 -- )
|
: push-either ( elt quot accum1 accum2 -- )
|
||||||
>r >r keep swap r> r> ? push ; inline
|
>r >r keep swap r> r> ? push ; inline
|
||||||
|
@ -214,3 +214,9 @@ PRIVATE>
|
||||||
|
|
||||||
: attempt-each ( seq quot -- result )
|
: attempt-each ( seq quot -- result )
|
||||||
(each) iterate-prep (attempt-each-integer) ; inline
|
(each) iterate-prep (attempt-each-integer) ; inline
|
||||||
|
|
||||||
|
: ?nth* ( n seq -- elt/f ? )
|
||||||
|
2dup bounds-check? [ nth-unsafe t ] [ 2drop f f ] if ; flushable
|
||||||
|
|
||||||
|
: nths ( indices seq -- seq' )
|
||||||
|
[ swap nth ] with map ;
|
||||||
|
|
Loading…
Reference in New Issue