Skip to content

Instantly share code, notes, and snippets.

@vasco3
Created September 18, 2013 09:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vasco3/6606639 to your computer and use it in GitHub Desktop.
Save vasco3/6606639 to your computer and use it in GitHub Desktop.
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?
/*
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?
*/
// determine start number = n ie. 20
function getSmallestDivisor(n){
var i = n;
// if not 0 then i++
function checkI(i){
for (var j = 1; j <= n; j++) {
// loop 20 % i where i goes from 1 to 20 must % = 0
if( i % j !== 0 ){ return false; }
};
return true;
}
// break loop when n all are 0
while( !(checkI(i)) ){ i+=n; }
return i;
}
@ImpulseTheFox
Copy link

232792560

@anktxox
Copy link

anktxox commented Jul 2, 2023

Thanksss

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment