Programming-Idioms

History of Idiom 31 > diff from v52 to v53

Edit summary for version 53 :
New Kotlin implementation by user [miguel]

Version 52

2019-09-26, 19:25:06

Version 53

2019-09-26, 21:54:17

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
fun f(i: Int): Int = when (i) {
    0 -> 1
    else -> i * f(i - 1)
}