Anonymous user
Pythagorean triples: Difference between revisions
→{{header|REXX}}: added separator line for subroutine; made REXX code compliant, added whitespace. -- ~~~~
(→{{header|REXX}}: added separator line for subroutine; made REXX code compliant, added whitespace. -- ~~~~) |
|||
Line 1,603:
=={{header|REXX}}==
A brute force approach.
▲/*count the number of Pythagorean triples that exist given a maximum */
/* perimeter of N, and also count how many of them are primatives. */
parse arg n .; if n=='' then n=100
trips=0
prims=0
do a=3 to n%3; aa=a*a
do b=a+1 /*triangle can't be isosceles. */
ab=a+b /*compute partial perimeter. */
Line 1,628 ⟶ 1,627:
say 'max perimeter='n " Pythagorean triples="trips ' primatives='prims
exit
/*------------------------------------GCD subroutine--------------------*/
gcd: procedure; arg x,y; do until _==0; _=x//y; x=y; y=_; end; return x</lang>
▲Output when using the input of:
▲<pre style="height:10ex;overflow:scroll">
max perimeter=100 Pythagorean triples=17 primatives=7
</pre>
|