Jump to content

Special pythagorean triplet: Difference between revisions

→‎{{header|ALGOL 68}}: Some optimisations
(timing)
(→‎{{header|ALGOL 68}}: Some optimisations)
Line 9:
{{trans|Wren}}
...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, a < b < c #
FOR a TO 1000 OVER 3 DO
INT a2 = a * a;
FOR b FROM a + 1 TO 1000 WHILE INT a plus b = a + b;
WHILE INT ac plus b = 1000 - a +plus b;
a plus b < 1000 c > b
DO
INTIF ca2 =+ 1000b*b -= ac*c plus b;THEN
print( ( "a = print(", whole( "a, *0 b), *", cb = ", whole( ab, *0 b), *", c = ", whole( c, 0 ), newline ) );
IF c > b THEN
IFprint( a2( "a + b*b + c = ", whole( a plus b + c*c, 0 ), newline ) THEN);
print( ( "a =* ",b whole(* a, 0 ), ", bc = ", whole( b,a 0* ),b ", c = ", whole(* 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
OD
3,053

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.