Project Euler Problem 4 (PHP)

Problem 4

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.

Script

Execution Time: 1.3709 seconds

$start = 999;
$r = array();

for ($x = $start; $x >= 100; $x--) {
    for ($y=$start; $y >= 100; $y--) {
        $p = $x*$y;
        if ($p == strrev($p)) {
            $r[] = $p;
        }
    }
}

rsort($r, SORT_NUMERIC);

echo $r[0].PHP_EOL;
This entry was posted in PHP, Programming, Project Euler and tagged , , , . Bookmark the permalink.

2 Responses to Project Euler Problem 4 (PHP)