Special pythagorean triplet: Difference between revisions

→‎{{header|ALGOL 68}}: Replaced with a solution using Euclid's formula, based on the XPL0 sample
(Realize in F#)
(→‎{{header|ALGOL 68}}: Replaced with a solution using Euclid's formula, based on the XPL0 sample)
Line 7:
<br><br>
=={{header|ALGOL 68}}==
Using Euclid's formula, as in the XPL0 sample
{{trans|Wren}}
...but doesn't stop on the first solution (thus verifying there is only one).
<lang algol68>BEGIN # find the product of the of the Pythagorian triplet a, b, c where: a + b + c = 1000, a < b < c #
# a + b + c = 1000, a2 + b2 = c2, a < b < c #
FOR a TO 1000 OVER 3 DO
INT a2sqrt 1000 = aENTIER sqrt( *1000 a);
FOR bn FROMTO a + 1 TOsqrt 1000 WHILE INT a plus b = aOVER +2 b;DO
FOR m FROM n + 1 TO INT c =sqrt 1000 - a plus b;DO
# a = m^2 - n^2, b = 2mn, c = m^2 + n^2 ( Euclid's formula ), so c > b #
# a + b + c = m^2 - n^2 + 2mn + m^2 + n^2 = 2( m^2 + mn ) = 2m( m + n ) #
DO
IF a2m * ( m + b*bn ) = c*c500 THEN
print( ( "a = ",INT whole( a, 0 ), ", bm2 = ",m whole(* bm, 0 ), ", cn2 = ", whole( c, 0 ), newlinen )* )n;
print( ( "a + bINT + ca = ", whole( a plus b + c, 0 ), newlinem2 )- )n2;
print( ( "a * INT b * c = ", whole( a2 * bm * c, 0 ), newline ) )n;
FI INT c = m2 + n2;
print( ( "a = ", whole( a, 0 ), ", b = ", whole( b, 0 ), ", c = ", whole( c, 0 ), newline ) );
print( ( "a * b * c = ", whole( a * b * c, 0 ), newline ) )
FI
OD
OD
END
OD</lang>
{{out}}
<pre>
a = 200375, b = 375200, c = 425
a + b + c = 1000
a * b * c = 31875000
</pre>
3,028

edits