Project Euler.net Answers
Problem 4
Solved on 2/26/2008
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.
Product1:913Product2:993
Answer: 906,609
$answer = 0;
for($oc = 999; $oc>1; $oc--){
for($ic = 999; $ic>1; $ic--){
if($this->isPal($ic*$oc)){
if($ic*$oc > $answer){
$answer = $ic*$oc;
p1 = $ic;
$p2 = $oc;
}
}
}
}
function isPal($val){
$rev = strrev($val);
if(strlen($val) % 2 == 0){
$length = strlen($val)/2;
return (substr($val,0,$length) == substr($rev,0,$length));
}else{
$length = (strlen($val)-1)/2;
return (substr($val,0,$length) == substr($rev,0,$length));
}
}