Anonymous user
Special pythagorean triplet: Difference between revisions
→{{header|REXX}}: added an option to allow more than one solution to be found.
Thundergnat (talk | contribs) (→{{header|Raku}}: return the product as well) |
(→{{header|REXX}}: added an option to allow more than one solution to be found.) |
||
Line 296:
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 /*precompute squares up to HI. */▼
end /*j*/▼
hi2= hi-2
#= 0 /*#: the number of solutions found. */
do a=1 for hi2; aa= @.a /*go hunting for solutions to equations*/
do b=a+1 for hi2-a; ab= a + b /*calculate sum of two (A,B) squares.*/
Line 308:
if @.c \== aabb then iterate /*Square\=A^2+B^2? Then keep searching*/
abc= ab + c /*compute the sum of A + B + C */
if abc == s then
if abc > s then iterate b /* " " > S? Then stop with C's.*/
end /*c*/
end /*b*/
end /*a*/
say # ' solutions found.'
say ' a=' a " b=" b ' c=' c▼
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
▲show: #= # + 1; say ' a=' a " b=" b ' c=' c; exit 0
/*replace EXIT 0 with RETURN to find more possible solutions─────┘ */</lang>
{{out|output|text= when using the default inputs:}}
<pre>
|