From: Tanaka Akira Date: 2012-02-17T22:55:31+09:00 Subject: Re: Factorial 2012/2/17 Junayeed Ahnaf Nirjhor : > > What is the most efficient way in Ruby to calculate the factorial of any > given sum? Is there any way to make it as fast as in C? > > Complexity doesn't matter as long as it works correctly. How about Math.gamma(n+1).to_i for fact(n) assuming n <= 22 ? If the restriction, n <= 22 is not acceptable, table lookup is another option. I think C is not so useful here because fact(21) overflows 64bit signed int. -- Tanaka Akira