Programming-Idioms

History of Idiom 31 > diff from v56 to v57

Edit summary for version 57 :
[Rust] Avoid link shortener if possible

Version 56

2019-10-14, 12:23:57

Version 57

2020-03-20, 17:57:23

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
fn f(n: u32) -> u32 {
    if n < 2 {
        1
    } else {
        n * f(n - 1)
    }
}
Code
fn f(n: u32) -> u32 {
    if n < 2 {
        1
    } else {
        n * f(n - 1)
    }
}
Demo URL
http://is.gd/ZVwM65
Demo URL
https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=c3685c8dff86b4244235c67836861610