Programming-Idioms

History of Idiom 31 > diff from v9 to v10

Edit summary for version 10 :

Version 9

2015-08-23, 10:47:56

Version 10

2015-09-03, 17:18:13

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
f = Hash.new { |hash, i| hash[i] = i * hash[i -1] }
f[0] = 1
f[23] # => 25852016738884976640000
Comments bubble
Note that f is not a function but plain old `Hash` used as a cache for performance.