Project Euler – Problem 4

Problem

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.

Solution

$sum = 0;
$largest = 0;

for ($i = 100; $i < 1000; $i++) {
  for ($j = 100; $j < 1000; $j++) {
    $sum = $i * $j;

    if ($largest < $sum && isPanlindrome($sum)) {
      $largest = $sum;
    }
  }
}

echo $largest;

function isPanlindrome($num) {
  if ($num == strrev($num)) {
    return TRUE;
  } else {
    return FALSE;
  }
}