factorial ( n -- n! )


Vocabulary
math.combinatorics

Inputs and outputs
na non-negative integer
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 math.ranges memoize sequences ;

IN: math.combinatorics

MEMO: factorial ( n -- n! )
dup 1 > [ [1,b] product ] [ drop 1 ] if ;