Gaussian primes: Difference between revisions

Content added Content deleted
(julia example)
Line 180: Line 180:
function testgaussprimes(lim = 10)
function testgaussprimes(lim = 10)
testvals = map(c -> c[1] + im * c[2], collect(Iterators.product(-lim:lim, -lim:lim)))
testvals = map(c -> c[1] + im * c[2], collect(Iterators.product(-lim:lim, -lim:lim)))
gprimes = sort!(filter(c -> isGaussianprime(c) && norm(c) < lim, testvals), by = x -> norm(x)^2)
gprimes = sort!(filter(c -> isGaussianprime(c) && norm(c) < lim, testvals), by = norm)
println("Gaussian primes within $lim of the origin on the complex plane:")
println("Gaussian primes within $lim of the origin on the complex plane:")
foreach(p -> print(lpad(p[2], 10), p[1] % 10 == 0 ? "\n" : ""), enumerate(gprimes)) # print
foreach(p -> print(lpad(p[2], 10), p[1] % 10 == 0 ? "\n" : ""), enumerate(gprimes)) # print
Line 201: Line 201:
8 - 5im 5 + 8im -4 + 9im -4 - 9im 9 + 4im -9 + 4im 9 - 4im -9 - 4im 4 - 9im 4 + 9im
8 - 5im 5 + 8im -4 + 9im -4 - 9im 9 + 4im -9 + 4im 9 - 4im -9 - 4im 4 - 9im 4 + 9im
</pre>
</pre>



=={{header|Phix}}==
=={{header|Phix}}==