DEV Community

loading...

Discussion on: Project Euler #4 - Largest Palindrome Product

Collapse
stephanie profile image
Stephanie Handsteiner

Am still able to just copy and paste from my Euler GitHub repo. 😂

PHP again

$largestThreeDig = 999;
$largestPalindrome = 0;
for($l = $largestThreeDig; $l > 0 && $l * $largestThreeDig > $largestPalindrome; $l--) {
    for($p = $l * $largestThreeDig; $p > $largestPalindrome; $p -= $l) {
        if((string)$p === strrev((string)$p)) {
            $largestPalindrome = $p;
        }
    }
}
 echo "Largest Palindrome: $largestPalindrome\n";
Collapse
maxart2501 profile image
Massimo Artizzu

This is another solution that I consider working in this particular case (3 digits) but not actually correct in the general case. I explained it here: dev.to/maxart2501/comment/b9me