Created
April 22, 2019 20:10
-
-
Save gavinsykes/857b3d58861c4b2951001cf72f3c8043 to your computer and use it in GitHub Desktop.
This file contains 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
function euler_9($n) { | |
$a = $b = $c = 1; | |
for ($a = 1;$a <= $n-2;$a++) { | |
for ($b = 1; $b <= $n-1-$a;$b++) { | |
$c = $n - $a - $b; | |
if (pythag_trip($a,$b,$c)) { | |
return $a . ', ' . $b . ' and ' . $c . ' make ' . $a*$b*$c . '.'; | |
} | |
} | |
} | |
} | |
function pythag_trip($a,$b,$c) { | |
if ($a**2 + $b**2 == $c**2 || $a**2 + $c**2 == $b**2 || $b**2 + $c**2 == $a**2) { | |
return true; | |
} | |
} | |
echo euler_9(1000); // Returns "200, 375 and 425 make 31875000." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment