Created
April 26, 2015 16:17
-
-
Save saltavenger/ba43828d4aa229bfa79e to your computer and use it in GitHub Desktop.
Class problems
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
/* Practice Problem 1 | |
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? | |
*/ | |
/* answer = 232,792,560 ...this works but is probably not the best way to do it | |
better answer = finding prime factorization of each num and multiplying to get LCM unclear on math*/ | |
var startNum = 20, | |
match = false; | |
while(match === false){ | |
match = checkMatch(startNum); | |
if(match === false){ | |
startNum++; | |
} | |
} | |
console.log(startNum); | |
function checkMatch(num){ | |
for(count = 1; count <= 20; count++){ | |
if(num%count !== 0){ | |
match = false; | |
break; | |
} | |
else{ | |
match = true; | |
} | |
} | |
return match; | |
} | |
/* Practice Problem 2 | |
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. | |
Find the largest palindrome made from the product of two 3-digit numbers. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment