Last active
September 30, 2015 12:27
-
-
Save egeozcan/1788749 to your computer and use it in GitHub Desktop.
Project Euler Problem 4 - JavaScript Solution
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
console.time("p"); | |
console.log(function () { | |
var x, y, z, i = 999, latestPalindrome = 0, palindromeDivider = 0; | |
for (x = 9; x > 0; x--) { | |
for (y = 9; y >= 0; y--) { | |
for (z = 9; z >= 0; z--) { | |
latestPalindrome = 100001 * x + 10010 * y + 1100 * z; | |
for (i = 999; i >= 100; i--) { | |
if (latestPalindrome % i === 0) { | |
palindromeDivider = latestPalindrome / i | |
if(palindromeDivider > 999)break; | |
if (palindromeDivider >= 100) { | |
return [ | |
"our palindrome is ", | |
palindromeDivider, " x ", i, | |
" = ", latestPalindrome ].join(""); | |
} | |
} | |
} | |
} | |
} | |
} | |
}()); | |
console.timeEnd("p"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment