+ 8
Factorial Challenge
Make a program that can calculate the factorial of any number and try to make it as fast as possible. You can make it in any language.
7 Answers
+ 7
This would work with ANY number, and by ANY I mean also decimal ones:
var g = 7;
var C = [0.99999999999980993, 676.5203681218851, -1259.1392167224028,771.32342877765313, -176.61502916214059, 12.507343278686905, -0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7];
function gamma(z){
if(z < 0.5){
return Math.PI/(Math.sin(Math.PI*z)*gamma(1-z));
}else{
z -= 1;
var x = C[0];
for(var i = 1; i < g+2; i++){
x += C[i]/(z+i);
}
var t = z+g+0.5;
return Math.sqrt(2*Math.PI)*Math.pow(t,(z+0.5))*Math.exp(-t)*x;
}
}
var fact = function(x){
if(x == 0){
return 1;
}
return x*gamma(x);
}
alert(fact(1/2));
+ 9
Javascript:
var fact = function(n){
if(n == 0){
return 1;
}
return n*fact(--n);
}
+ 2
https://code.sololearn.com/c7OKn1aMi2zu/?ref=app
+ 1
https://code.sololearn.com/ci11y1PeLHvj/?ref=app
Factorial more than 20 just tried simply ...šš
+ 1
just try this powerful one
https://code.sololearn.com/c5cLMjWLF6W7/?ref=app