Pythagorean quadruples: Difference between revisions
Content added Content deleted
m (→Version 1) |
(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> |
<lang>const N = 2_200 |
||
const N = 2_200 |
|||
const N2 = N * N * 2 |
const N2 = N * N * 2 |
||
⚫ | |||
var |
|||
a2, d, s1, s2 = 0 |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
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 |
||
⚫ | |||
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}}== |