Function factorial

Source
pub fn factorial(n: usize) -> usize
Expand description

Returns n factorial.

ยงExamples

use combinatorial::factorial;

assert_eq!(factorial(0), 1);
assert_eq!(factorial(1), 1);
assert_eq!(factorial(2), 2);
assert_eq!(factorial(3), 6);

assert_eq!(factorial(10), (1..=10).product());

for n in 1..10 {
    assert_eq!(factorial(n), n * factorial(n - 1));
}