factorial ( n -- n! ) (original) (raw)

factorial ( n -- n! )

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 ;

IN: math.combinatorics

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