Created
November 19, 2013 07:00
-
-
Save pmgupte/7541357 to your computer and use it in GitHub Desktop.
PHP solution to Project Euler problem # 4.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Problem 4: Largest palindrome product | |
* | |
* 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. | |
*/ | |
$largest=101; | |
$l1 = $l2 = 999; | |
for ($i=999; $i>=100; $i--) { | |
for ($j=999; $j>=100; $j--) { | |
$k = $i*$j; | |
$kstr = "$k"; | |
if($kstr == strrev($kstr) && $k>$largest) { | |
$largest = $k; | |
$l1 = $i; | |
$l2 = $j; | |
} | |
} | |
} | |
echo "largest palindrome product of 3 digit nums = $largest = $l1 x $l2\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment