Pythagorean quadruples: Difference between revisions

Content added Content deleted
(Version 2: cleanup the code; removed useless variable, moved variable declarations, added missing final end of line in output.)
Line 1,248: Line 1,248:


===Version 2===
===Version 2===
<lang>import sequtils
<lang>const N = 2_200

const N = 2_200
const N2 = N * N * 2
const N2 = N * N * 2


var r = newSeq[bool](N + 1)
var
a2, d, s1, s2 = 0
s = 3
r = newSeq[bool](N + 1)
ab = newSeq[bool](N2 + 1)
var ab = newSeq[bool](N2 + 1)
for a in 1..N:
for a in 1..N:
a2 = a * a
let a2 = a * a
for b in a..N:
for b in a..N:
ab[a2 + b * b] = true
ab[a2 + b * b] = true


var s = 3
for c in 1..N:
for c in 1..N:
s1 = s
var s1 = s
s += 2
s += 2
s2 = s
var s2 = s
for d in c+1..N:
for d in (c+1)..N:
if ab[s1]: r[d] = true
if ab[s1]: r[d] = true
s1 += s2
s1 += s2
Line 1,277: Line 1,273:


{{out}}
{{out}}
<pre>1 2 4 5 8 10 16 20 32 40 64 80 128 160 256 320 512 640 1024 1280 2048 </pre>
<pre>
Same as Version 1.
</pre>


=={{header|Pascal}}==
=={{header|Pascal}}==