Last active
August 29, 2015 14:02
-
-
Save ajrob/81866bc9735394ab0b8d to your computer and use it in GitHub Desktop.
Euler Project Problem 5
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
// 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. | |
// What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? | |
var smallestNumber = 19; | |
var uDone = false; | |
while (!uDone) { | |
smallestNumber++; | |
for (var i = 1; i <= 20; i++){ | |
if(!isDivisible(i, smallestNumber)){ | |
break; | |
} | |
if( i == 20){ | |
uDone = true; | |
} | |
} | |
} | |
console.log(smallestNumber); | |
function isDivisible(divisor, dividend){ | |
if(dividend%divisor === 0){ | |
return true; | |
} else { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment