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.
i made this code to find the solution but the answer in Project Euler website still incorrect:
function Palindromic(x) {
var pal = parseInt(x.toString().split('').reverse().join(''));
if (pal === x)
return true;
else
return false;
}
var x = 100,
y = 100,
product = x * y;
for (x; x <= 999; x++) {
for (y = x; y <= 999; y++) {
product = x * y;
if (Palindromic(product)) {
console.log(x + '*' + y + '=' + product);
}
}
}
Is there a problem in my code?! anyway, the answer that i got was 888888 from 924*962
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111, 121, 131, 141, 151, 161, 171, 181, 191, 202, … (sequence A002113 in the OEIS). Palindromic numbers receive most attention in the realm of recreational mathematics.
The largest palindrome made from the product of two 3-digit numbers is 913 * 993 = 906609. Flowchart: There was a problem connecting to the server.
Now palindromic numbers which reads the same if read from backwards also. So such numbers are 11, 22, 33, 44, 55, 66, 77, 88 and 99. So there are 9 palindromic two digit numbers from 1 to 1000.
You can conclude that there are 900 palindromes withfive and 900 palindromes with six digits.
I don't think, there is a real problem with your code. You just do not filter for the largest product, which is not necessarily your last output. Just add an additional check for the largest product, e.g. like this:
var x, y, product, max = 0;
for (x = 100; x <= 999; x++) {
for (y = x; y <= 999; y++) {
product = x * y;
if (Palindromic(product)) {
if( max < product ) { // this is new
max = product;
console.log(x + '*' + y + '=' + product);
}
}
}
}
This returns
913*993=906609
as the largest result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With