| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: Pythagorean triples |
-> And very nicely, thank you; I haven't timed it on this box but it
-> got to solution #19,271 in very short order.
-> An excellent thread...
-> :-))
Right. With the PRINT disabled, it gets to that solution, on my
machine, in about six seconds! That's startling! More than 3000 triples
per second, on average. (The rate at which they are produced does slow
down as A gets larger, but not very rapidly. The reduced rate at which
A's are dealt with is largely compensated by the fact that there are
more valid triples per value of A.)
However... I am still trying to prove, analytically, that ALL valid
triples, in lowest terms, are of the form:
A = D * E
B = (E^2 - D^2) / 2
C = (E^2 + D^2) / 2
where D and E are odd positive integers. Could there be any valid
triples that are not of this form, and which are therefore not
generated by the program? I don't think so. The total numbers of
triples that the program produces are in agreement with the ones that
are produced by a brute-force-and-ignorance program that just hunts for
triples without using these formulae. So I am 99.9% sure that there are
no exceptions. But 100% would be nice. Can you, or Jasen, or anyone
else, come up with a proof? A couple of formulae that would let D and E
be calculated from A, B and C in "integer" arithmetic (i.e. no
square-roots, etc.) would constitute a good proof.
Still working on it...
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
SELECT CASE A MOD 4
CASE 0
A2 = A \ 2
FOR F = INT(SQR(Z# * A2)) TO 1 STEP -1
G = A2 \ F
IF G * F = A2 THEN
E = F + G
IF E MOD 2 THEN
D = G - F
B = D * E
GOSUB XX
END IF
END IF
NEXT
CASE IS 2
FOR D = INT(SQR(Z# * A)) - 1 OR 1 TO 1 STEP -2
E = A \ D
IF E * D = A THEN
B = ((E + D) * (E - D)) \ 2
GOSUB XX
END IF
NEXT
END SELECT
NEXT
END
XX:
U = B
V = A
DO WHILE V > 1
W = U MOD V
U = V
V = W
LOOP
IF V THEN
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™.