| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Pythagorean triples |
Well, I can't think of any more improvements to this program. The last
thing I tried, looking to see if A was divisible by any primes-squared,
and doing the common-factor test only if it was, turned out to waste
more time than it saved. It was a nice idea, but...
So here is the probably-final version. I'm not sure whether I've posted
this exact one previously, or not.
If anyone else can find any other shortcuts, or maybe develop a
completely adifferent and more efficient algorithm, I'd love to see
them.
dow
-------------------------------------------------------
' pythagorean triples
DEFLNG A-Z
Mn = 3 ' minimum length of shortest side
Mx = 10000 ' maximum length of shortest side
N = 0
Z# = SQR(2) - 1
CLS
FOR A = Mn TO Mx
T = A MOD 4
SELECT CASE T
CASE 0
S = A \ 2
FOR F = INT(SQR(Z# * S)) TO 1 STEP -1
G = S \ F
IF G * F = S THEN
IF (F XOR G) AND 1 THEN
E = F + G
D = G - F
GOSUB XX
END IF
END IF
NEXT
CASE IS 2
S = INT(SQR(Z# * A))
FOR D = S - 1 OR 1 TO 1 STEP -2
E = A \ D
IF E * D = A THEN GOSUB XX
NEXT
END SELECT
NEXT
END
XX:
U = E
V = D
DO WHILE V > 1
W = U MOD V
U = V
V = W
LOOP
IF V THEN
IF T THEN B = ((E + D) * (E - D)) \ 2 ELSE B = D * E
C = (E * E + D * D) \ 2
N = N + 1
PRINT N, , A, B, C
END IF
RETURN
-----------------------------------------------------
--- Platinum Xpress/Win/WINServer v3.0pr5
* Origin: The Bayman BBS,Toronto, (416)698-6573 - 1:250/514 (1:250/514)SEEN-BY: 633/267 270 @PATH: 250/514 123/500 106/2000 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.