Pythagorean triples: Difference between revisions

Content added Content deleted
(Second PL/I version included)
(added autohotkey)
Line 62: Line 62:
Up to 10 ** 9 : 1294080089 Triples, 70230484 Primitives</pre>
Up to 10 ** 9 : 1294080089 Triples, 70230484 Primitives</pre>


=={{header|AutoHotkey}}==
<lang autohotkey>#NoEnv
SetBatchLines, -1
#SingleInstance, Force

; Greatest common divisor, from http://rosettacode.org/wiki/Greatest_common_divisor#AutoHotkey
gcd(a,b) {
Return b=0 ? Abs(a) : Gcd(b,mod(a,b))
}

count_triples(max) {
primitives := 0, triples := 0, m := 2
while m <= (max / 2)**0.5
{
n := mod(m, 2) + 1
,p := 2*m*(m + n)
, delta := 4*m
while n < m and p <= max
gcd(m, n) = 1
? (primitives++
, triples += max // p)
: ""
, n += 2
, p += delta
m++
}
Return primitives " primitives out of " triples " triples"
}

Loop, 8
Msgbox % 10**A_Index ": " count_triples(10**A_Index)</lang>

{{out}}
<pre>10: 0 primitives out of 0 triples
100: 7 primitives out of 17 triples
1000: 70 primitives out of 325 triples
10000: 703 primitives out of 4858 triples
100000: 7026 primitives out of 64741 triples
1000000: 70229 primitives out of 808950 triples
10000000: 702309 primitives out of 9706567 triples
100000000: 7023027 primitives out of 113236940 triples</pre>


=={{header|BBC BASIC}}==
=={{header|BBC BASIC}}==