Logo

Programming-Idioms

History of Idiom 31 > diff from v43 to v44

Edit summary for version 44 by erlend.powell:
New Rust implementation by user [erlend.powell]

Version 43

2017-12-21, 03:23:16

Version 44

2019-07-06, 11:24:07

Idiom #31 Recursive factorial (simple)

Create recursive function f which returns the factorial of non-negative integer i, calculated from f(i-1)

Idiom #31 Recursive factorial (simple)

Create recursive function f which returns the factorial of non-negative integer i, calculated from f(i-1)

Code
pub fn factorial(num: u64) -> u64 {
    match num {
        0 => 1,
        1 => 1,
        _ => factorial(num - 1) * num,
    }
}