2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -0,0 +1,15 @@
|
|||
: fact ( n -- n-factorial )
|
||||
dup 0 = [ drop 1 ] [ dup 1 - fact * ] if ;
|
||||
|
||||
: choose ( n k -- n-choose-k )
|
||||
2dup - fact swap fact * swap fact swap / ;
|
||||
|
||||
! outputs 10
|
||||
5 3 choose .
|
||||
|
||||
! alternative using folds
|
||||
USE: math.ranges
|
||||
|
||||
! (product [n..k+1] / product [n-k..1])
|
||||
: choose-fold ( n k -- n-choose-k )
|
||||
2dup 1 + [a,b] product -rot - 1 [a,b] product / ;
|
||||
Loading…
Add table
Add a link
Reference in a new issue