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; |
||
INT c = 1000 - a plus b; |
|||
c > b |
|||
DO |
DO |
||
IF a2 + b*b = c*c THEN |
|||
⚫ | |||
IF c > b THEN |
|||
print( ( "a + b + c = ", whole( a plus b + c, 0 ), newline ) ); |
|||
print( ( "a * b * c = ", whole( a * b * c, 0 ), newline ) ) |
|||
print( ( "a + b + c = ", whole( a plus b + c, 0 ), newline ) ); |
|||
⚫ | |||
FI |
|||
FI |
FI |
||
OD |
OD |