math.combinatorics: faster version of factorial.
parent
cd9394f8c6
commit
f24e40800a
|
@ -1,6 +1,7 @@
|
||||||
USING: kernel math math.combinatorics math.combinatorics.private tools.test sequences ;
|
USING: kernel math math.combinatorics math.combinatorics.private tools.test sequences ;
|
||||||
IN: math.combinatorics.tests
|
IN: math.combinatorics.tests
|
||||||
|
|
||||||
|
[ 1 ] [ -1 factorial ] unit-test ! required by other math.combinatorics words
|
||||||
[ 1 ] [ 0 factorial ] unit-test
|
[ 1 ] [ 0 factorial ] unit-test
|
||||||
[ 1 ] [ 1 factorial ] unit-test
|
[ 1 ] [ 1 factorial ] unit-test
|
||||||
[ 3628800 ] [ 10 factorial ] unit-test
|
[ 3628800 ] [ 10 factorial ] unit-test
|
||||||
|
|
|
@ -18,7 +18,7 @@ IN: math.combinatorics
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: factorial ( n -- n! )
|
: factorial ( n -- n! )
|
||||||
iota 1 [ 1 + * ] reduce ;
|
dup 1 > [ [1,b] product ] [ drop 1 ] if ;
|
||||||
|
|
||||||
: nPk ( n k -- nPk )
|
: nPk ( n k -- nPk )
|
||||||
2dup possible? [ dupd - [a,b) product ] [ 2drop 0 ] if ;
|
2dup possible? [ dupd - [a,b) product ] [ 2drop 0 ] if ;
|
||||||
|
|
Loading…
Reference in New Issue