diff --git a/basis/math/combinatorics/combinatorics.factor b/basis/math/combinatorics/combinatorics.factor index c9bf5c6bf5..fd0ad7ba7b 100644 --- a/basis/math/combinatorics/combinatorics.factor +++ b/basis/math/combinatorics/combinatorics.factor @@ -32,13 +32,13 @@ PRIVATE> ] [ 1 + [ /mod ] keep swap ] produce reverse 2nip ; + 0 [ over 0 > ] [ 1 + [ /mod ] keep swap ] produce reverse! 2nip ; : (>permutation) ( seq n -- seq ) - [ '[ _ dupd >= [ 1 + ] when ] map ] keep prefix ; + [ '[ _ dupd >= [ 1 + ] when ] map! ] keep prefix ; : >permutation ( factoradic -- permutation ) - reverse 1 cut [ (>permutation) ] each ; + reverse! 1 cut [ (>permutation) ] each ; : permutation-indices ( n seq -- permutation ) length [ factoradic ] dip 0 pad-head >permutation ; @@ -147,7 +147,7 @@ C: combo :: combination-indices ( m combo -- seq ) combo m combo dual-index combinadic - combo seq>> length 1 - swap [ - ] with map ; + combo seq>> length 1 - swap [ - ] with map! ; : apply-combination ( m combo -- seq ) [ combination-indices ] keep seq>> nths ; diff --git a/extra/project-euler/common/common.factor b/extra/project-euler/common/common.factor index 0e06e9eb93..33bd1fd408 100644 --- a/extra/project-euler/common/common.factor +++ b/extra/project-euler/common/common.factor @@ -80,7 +80,7 @@ PRIVATE> ] if ; : number>digits ( n -- seq ) - [ dup 0 = not ] [ 10 /mod ] produce reverse nip ; + [ dup 0 = not ] [ 10 /mod ] produce reverse! nip ; : number-length ( n -- m ) abs [