Skip to content

Instantly share code, notes, and snippets.

@egeozcan
Last active September 30, 2015 12:27
Show Gist options
  • Save egeozcan/1788749 to your computer and use it in GitHub Desktop.
Save egeozcan/1788749 to your computer and use it in GitHub Desktop.
Project Euler Problem 4 - JavaScript Solution
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