Project Euler Question
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a2 + b2 = c2
For example, 32 + 42 = 9 + 16 = 25 = 52.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.Find the product abc.
File Status: Solution File found. Code from the function code_solution_9 will be used
Solution: 200 * 375 * 425 = 31875000
Solution Code:
<?php
function code_solution_9() {
for($a = 3; $a<=332; $a++) {
for($b = $a+1; $a+($b*2) <=1000; $b++) {
$c = 1000-$a-$b;
if(pow($a,2)+pow($b,2) == pow($c,2)) {
return "$a * $b * $c = " . $a*$b*$c;
}
}
}
}