Created
May 31, 2010 20:48
-
-
Save clauswitt/420267 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sys = require('sys'); | |
var Euler5 = function() { | |
var factorial = function(num) { | |
var res = 1; | |
for(var i=num;i>1;i--) { | |
res = i*res; | |
} | |
return res; | |
} | |
var isDivisor = function(number, candidate) { | |
//If a division has no remainder the candidate is a divisor of number. | |
return ((number%candidate)==0); | |
} | |
var checkDivisors = function(number, maxNumber) { | |
for(var i=1;i<=maxNumber;i++) { | |
if(!isDivisor(number, i)) { | |
return false; | |
} | |
} | |
return true; | |
} | |
var getSmallestEvenlyDivisable = function(maxNumber) { | |
maxResult = factorial(maxNumber); | |
for(var i=maxNumber;i<=maxResult;i++) { | |
if(checkDivisors(i, maxNumber)) { | |
sys.puts('Result: ' + i); | |
break; | |
} | |
} | |
}; | |
getSmallestEvenlyDivisable(20); | |
}; | |
new Euler5(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment