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.
<lang rexx>/*countREXX thepgm counts number of Pythagorean triples that exist given a maximum */
<lang rexx>
/*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 /*get "N". If none, then assume.*/
trips=0
prims=0
 
do a=3 to n%3; aa=a*a /*limit side to 1/3 of perimeter.*/
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 '''output''' when using the input of: <tt> 100 </tt>
</lang>
<pre style="height:10ex;overflow:scroll">
Output when using the input of:
<br><br>
100
<pre style="height:10ex;overflow:scroll">
max perimeter=100 Pythagorean triples=17 primatives=7
</pre>