/
0004.html
executable file
·33 lines (30 loc) · 957 Bytes
/
0004.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<p>A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 x 99.</p>
<p>Find the largest palindrome made from the product of two 3-digit numbers.</p>
<script>
(function(){
var i = 999, j = 999, highest = 0, palindromes = [];
while (i > 0) {
while (j > 0) {
var pal = determinePalindrome(i * j + "");
if (pal)
palindromes.push(i * j);
j -= 1;
}
i -= 1;
j = 99;
}
function determinePalindrome(k) {
//determine the number of pairs and loop through each pair to compare values
for (var m = 0; m < k.length; m++){
var first, last;
first = k.charAt(m);
last = k.charAt(k.length - 1 - m);
if (first !== last)
return false;
}
return true;
}
palindromes.sort(function(palindromes,sorted){return palindromes-sorted;});
document.write(palindromes[palindromes.length - 1]);
})();
</script>