Gaussian primes: Difference between revisions

Added 11l
(→‎{{header|Quackery}}: fast graphics)
(Added 11l)
Line 33:
 
 
 
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">
F is_prime(a)
I a == 2
R 1B
I a < 2 | a % 2 == 0
R 0B
L(i) (3 .. Int(sqrt(a))).step(2)
I a % i == 0
R 0B
R 1B
 
F is_gaussian_prime(n)
V (r, c) = (Int(abs(n.real)), Int(abs(n.imag)))
R is_prime(r * r + c * c) | (c == 0 & is_prime(r) & (r - 3) % 4 == 0) | (r == 0 & is_prime(c) & (c - 3) % 4 == 0)
 
F norm(c)
R c.real * c.real + c.imag * c.imag
 
V limitsquared = 100
V lim = Int(sqrt(limitsquared))
V testvals = multiloop((-lim .< lim), (-lim .< lim), (r, c) -> Complex(r, c))
testvals = testvals.filter(c -> is_gaussian_prime(c) & norm(c) < :limitsquared)
V gprimes = sorted(enumerate(testvals).map((i, c) -> (c, i)), key' c -> (norm(c[0]), c[1]))
print(‘Gaussian primes within ’lim‘ of the origin on the complex plane:’)
L(c) gprimes
print(String(c[0]).ljust(9), end' I (L.index + 1) % 10 == 0 {"\n"} E ‘’)
</syntaxhighlight>
 
{{out}}
<pre>
Gaussian primes within 10 of the origin on the complex plane:
-1-1i -1+1i 1-1i 1+1i -2-1i -2+1i -1-2i -1+2i 1-2i 1+2i
2-1i 2+1i -3 -3i 3i 3 -3-2i -3+2i -2-3i -2+3i
2-3i 2+3i 3-2i 3+2i -4-1i -4+1i -1-4i -1+4i 1-4i 1+4i
4-1i 4+1i -5-2i -5+2i -2-5i -2+5i 2-5i 2+5i 5-2i 5+2i
-6-1i -6+1i -1-6i -1+6i 1-6i 1+6i 6-1i 6+1i -5-4i -5+4i
-4-5i -4+5i 4-5i 4+5i 5-4i 5+4i -7 -7i 7i 7
-7-2i -7+2i -2-7i -2+7i 2-7i 2+7i 7-2i 7+2i -6-5i -6+5i
-5-6i -5+6i 5-6i 5+6i 6-5i 6+5i -8-3i -8+3i -3-8i -3+8i
3-8i 3+8i 8-3i 8+3i -8-5i -8+5i -5-8i -5+8i 5-8i 5+8i
8-5i 8+5i -9-4i -9+4i -4-9i -4+9i 4-9i 4+9i 9-4i 9+4i
</pre>
 
=={{header|ALGOL 68}}==
1,453

edits