factorial ( n -- n! ) (original) (raw)
Vocabulary
math.combinatorics
Inputs
n | a non-negative integer |
---|
Outputs
n! | an integer |
---|
Word description
Outputs the product of all positive integers less than or equal to n.
Examples
USING: math.combinatorics prettyprint ; 4 factorial .
24
Definition
USING: kernel math ranges sequences ;
: factorial ( n -- n! )
dup 1 > [ [1..b] product ] [ drop 1 ] if ;