Special pythagorean triplet: Difference between revisions
Content added Content deleted
(→{{header|ALGOL 68}}: Show the number of iterations reuired and don't stop after the first (only) solution has been found.) |
SqrtNegInf (talk | contribs) (Added Perl) |
||
Line 554: | Line 554: | ||
b: 375 |
b: 375 |
||
c: 425</pre> |
c: 425</pre> |
||
=={{header|Perl}}== |
|||
<lang perl>use strict; |
|||
use warnings; |
|||
for my $a (1 .. 998) { |
|||
my $a2 = $a**2; |
|||
for my $b ($a+1 .. 999) { |
|||
my $c = 1000 - $a - $b; |
|||
last if $c < $b; |
|||
print "$a² + $b² = $c²\n$a + $b + $c = 1000\n" and last if $a2 + $b**2 == $c**2 |
|||
} |
|||
}</lang> |
|||
{{out}} |
|||
<pre>200² + 375² = 425² |
|||
200 + 375 + 425 = 1000</pre> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |