Created
July 14, 2013 03:41
-
-
Save atushi/5993105 to your computer and use it in GitHub Desktop.
Project Euler . Problem 4 . Largest palindrome product : 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.
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
var check = function() { | |
rtnNum = a*b; | |
console.log(a + ' * ' + b + ' = ' + rtnNum); | |
strAns = String(rtnNum); | |
flag = true; | |
// check | |
for (var x=0; x<strAns.length/2; x++) { | |
//console.log('strAns[x] : ' + strAns[x]); | |
//console.log('strAns[strAns.length-(x+1)] : ' + strAns[strAns.length-(x+1)]); | |
if (strAns[x] != strAns[strAns.length-(x+1)]) { flag = false; return 0; } | |
} | |
return rtnNum; | |
}; | |
var DEFAULTNUM = 999; | |
var a = DEFAULTNUM; | |
var b = DEFAULTNUM; | |
var ans = 0; | |
var flag; | |
for (; a>=(DEFAULTNUM/1.1); a--) { | |
tmp = check(); | |
if (ans < tmp) ans = tmp; | |
for (; b>=(DEFAULTNUM/1.1); b--) { | |
tmp = check(); | |
if (ans < tmp) ans = tmp; | |
} | |
b = a; | |
} | |
console.log(ans); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment