Categories: archive |code

Project Euler #5

In JavaScript:

(function(){
  //this is some ugly looking code
  //real number is 232792560
  //js takes forever to find the right answer, so changed num to the answer minus 1.
  //Change low to watch in action
  var num = 232792559, isNotDivisible = true, currentDivisible = false;

  while (isNotDivisible){
    for (var i = 1; i < 21; i++){
      var currentDivisible = testDivisible(num, i);
      if (!currentDivisible)
        break;
    }
    num += 1;
    isNotDivisible = !currentDivisible;
  }

  function testDivisible(num, i){
    if (num % i !== 0)
      return false;
    else
      return true;
  }
  document.write(num - 1);
})();

on GitHub