Pythagorean quadruples: Difference between revisions

Version 1: cleaned up the code; added a template; added missing final newline in output.
(Added 11l)
(Version 1: cleaned up the code; added a template; added missing final newline in output.)
Line 1,224:
===Version 1===
<lang>import math
import sequtils
 
const N = 2_200
 
template isOdd(n: int): bool = (n and 1) != 0
var
 
d, b = 0
var r = newSeq[bool](N + 1)
 
for a in 1..N:
for b in a..N:
if a.isOdd and b.isOdd: continue
var aabb = 0
iflet aabb = (a and* 1).boola and+ (b and* 1).bool: continueb
aabb = a * a + b * b
for c in b..N:
varlet aabbcc = 0aabb + c * c
aabbcc = aabb + c * c
d = sqrt(aabbcc.float).int
if aabbcc == d * d and d <= N: r[d] = true
 
for i in 1..N:
if not r[I]: stdout.write i, " "</lang>
echo()
 
{{out}}
Anonymous user