Pythagorean triples: Difference between revisions

m
→‎using single evenness for determinacy: added whitespace, changed some comments.
m (→‎using GCD for determinacy: changes come comments, added whitespace.)
m (→‎using single evenness for determinacy: added whitespace, changed some comments.)
Line 3,614:
/*──────────────────── perimeter of N, and also counts how many of them are primitives.*/
parse arg N . /*obtain optional argument from the CL.*/
if N=='' | N=="," then N=100 100 /*Not specified? Then use the default.*/
@.= 0; do j=1 for N; @.j= j*j; end /*pre-compute some squares. */
N66= N * 2%3 /*calculate 2/3 of N (for a+b). */
P= 0; T= 0; do a=3 to N%3 /*limit side to 1/3 of the perimeter.*/
Line 3,623:
aabb= @.a + @.b /*compute the sum of a²+b² (shortcut)*/
do c=b + 1 /*compute the value of the third side. */
if aEven then if c//2==0 then iterate /*both A&C even? Skip it*/
if ab+c>n then iterate a /*a+b+c > perimeter? Try different A. */
if @.c > aabb then iterate b /*is c² > a²+b² ? Try a" " different B. */
if @.c\==aabb then iterate /*is c² ¬= a²+b² ? Try a" " different C. */
if @.a.b.c then iterate /*Is this a duplicate? Then try again.*/
T= T + 1 /*Eureka! We found a Pythagorean triple*/