Special pythagorean triplet: Difference between revisions
Content deleted Content added
m →{{header|REXX}}: changed a word in the REXX section header. |
m →{{header|REXX}}: further optimized the DO loops. |
||
Line 278:
Also, there were multiple shortcuts to limit an otherwise exhaustive search; Once a sum or a square was too big,
<br>the next integer was used.
<lang rexx>/*REXX pgm computes
parse arg s hi . /*obtain optional argument from the CL.*/
if s=='' | s=="," then s= 1000 /*Not specified? Then use the default.*/
if hi=='' | hi=="," then hi= 1000 /* " " " " " " */
do j=1 for hi; @.j= j*j
end /*j*/
hi2= hi-2
do a=1 for
do b=a+1
if ab>hi then iterate a
aabb= aa + @.b
do c=b+1
if @.c > aabb then iterate b
if @.c \== aabb then iterate
abc= ab + c
if abc == s then leave a
if abc > s then iterate b
end /*c*/
end /*b*/
end /*a*/
say ' a=' a " b=" b ' c=' c▼
▲say ' a=' a " b=" b ' c=' c
exit 0 /*stick a fork in it, we're all done. */</lang>
{{out|output|text= when using the default inputs:}}
|