Special pythagorean triplet: Difference between revisions

→‎{{header|ALGOL W}}: Make it closer to the Wren original and small optimisations
(→‎{{header|ALGOL 68}}: Some optimisations)
(→‎{{header|ALGOL W}}: Make it closer to the Wren original and small optimisations)
Line 34:
...but doesn't stop on the first solution (thus verifying there is only one).
<lang algolw>% find the Pythagorian triplet a, b, c where a + b + c = 1000 %
for a := 1 until 1000 div 3 do begin
integer a2, b;
a2 := a * a;
for b := a + 1; until 1000 do begin
while a + b < 1000 do begin
integer c;
c := 1000 - ( a + b );
if c ><= b then begingoto endB;
if a2 + b*b = c*c then begin
write( i_w := 1, s_w := 0, "a = ", a, ", b = ", b, ", c = ", c );
write( i_w := 1, s_w := 0, "a + b + c = ", a + b + c );
write( i_w := 1, s_w := 0, "a * b * c = ", a * b * c )
end if_a2_plus_b2_e_c2 ;
end if_b_gt_c ;
b := b + 1
end while_a_plus_b_lt_1000for_b ;
endB:
end for_a .</lang>
{{out}}
3,060

edits