Programming-Idioms

History of Idiom 31 > diff from v36 to v37

Edit summary for version 37 :
New Ruby implementation by user [programming-idioms.org]

Version 36

2017-03-19, 19:31:32

Version 37

2017-03-19, 20:56:31

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
fac = Hash.new {|h, i| h[i] = i * h[i-1] }.tap {|h| h[0] = 1 }