Special pythagorean triplet: Difference between revisions

Content added Content deleted
(timing)
(→‎{{header|ALGOL 68}}: Some optimisations)
Line 9: Line 9:
{{trans|Wren}}
{{trans|Wren}}
...but doesn't stop on the first solution (thus verifying there is only one).
...but doesn't stop on the first solution (thus verifying there is only one).
<lang algol68># find the Pythagorian triplet a, b, c where a + b + c = 1000 #
<lang algol68># find the Pythagorian triplet a, b, c where a + b + c = 1000, a < b < c #
FOR a TO 1000 DO
FOR a TO 1000 OVER 3 DO
INT a2 = a * a;
INT a2 = a * a;
FOR b FROM a + 1
FOR b FROM a + 1 TO 1000 WHILE INT a plus b = a + b;
WHILE INT a plus b = a + b;
INT c = 1000 - a plus b;
a plus b < 1000
c > b
DO
DO
INT c = 1000 - a plus b;
IF a2 + b*b = c*c THEN
print( ( "a = ", whole( a, 0 ), ", b = ", whole( b, 0 ), ", c = ", whole( c, 0 ), newline ) );
IF c > b THEN
IF a2 + b*b = c*c THEN
print( ( "a + b + c = ", whole( a plus b + c, 0 ), newline ) );
print( ( "a = ", whole( a, 0 ), ", b = ", whole( b, 0 ), ", c = ", whole( c, 0 ), newline ) );
print( ( "a * b * c = ", whole( a * b * c, 0 ), newline ) )
print( ( "a + b + c = ", whole( a plus b + c, 0 ), newline ) );
print( ( "a * b * c = ", whole( a * b * c, 0 ), newline ) )
FI
FI
FI
OD
OD