Skip to content

Instantly share code, notes, and snippets.

@clauswitt
Created May 31, 2010 20:48
Show Gist options
  • Save clauswitt/420267 to your computer and use it in GitHub Desktop.
Save clauswitt/420267 to your computer and use it in GitHub Desktop.
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