Gaussian primes: Difference between revisions

Added FreeBASIC
m (→‎{{header|Wren}}: Changed to Wren S/H)
(Added FreeBASIC)
Line 279:
-9-4i -9+4i -8-7i -8-5i -8-3i -8+3i -8+5i -8+7i -7-8i -7-2i -7 -7+2i -7+8i -6-5i -6-1i -6+1i -6+5i -5-8i -5-6i -5-4i -5-2i -5+2i -5+4i -5+6i -5+8i -4-9i -4-5i -4-1i -4+1i -4+5i -4+9i -3-8i -3-2i -3 -3+2i -3+8i -2-7i -2-5i -2-3i -2-1i -2+1i -2+3i -2+5i -2+7i -1-6i -1-4i -1-2i -1-1i -1+1i -1+2i -1+4i -1+6i 0-7i 0-3i 0+3i 0+7i 1-6i 1-4i 1-2i 1-1i 1+1i 1+2i 1+4i 1+6i 2-7i 2-5i 2-3i 2-1i 2+1i 2+3i 2+5i 2+7i 3-8i 3-2i 3 3+2i 3+8i 4-9i 4-5i 4-1i 4+1i 4+5i 4+9i 5-8i 5-6i 5-4i 5-2i 5+2i 5+4i 5+6i 5+8i 6-5i 6-1i 6+1i 6+5i 7-8i 7-2i 7 7+2i 7+8i 8-7i 8-5i 8-3i 8+3i 8+5i 8+7i 9-4i 9+4i
</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="vbnet">'#include "isprime.bas"
 
Function isGaussianPrime(realPart As Integer, imagPart As Integer) As Boolean
Dim As Integer norm = realPart * realPart + imagPart * imagPart
If realPart = 0 Andalso imagPart <> 0 Then
Return (Abs(imagPart) Mod 4 = 3) Andalso isPrime(Abs(imagPart))
Elseif imagPart = 0 And realPart <> 0 Then
Return (Abs(realPart) Mod 4 = 3) Andalso isPrime(Abs(realPart))
Else
Return isPrime(norm)
End If
End Function
 
Print "Gaussian primes within 10 of the origin on the complex plane:"
Dim As Integer i, j, norm, radius = 50
For i = -radius To radius
For j = -radius To radius
norm = i * i + j * j
If norm < 100 Andalso isGaussianPrime(i, j) Then
Print Using "##"; i;
Print Iif(j >= 0, "+", "");
Print j & "i",
End If
Next j
Next i
 
Sleep</syntaxhighlight>
 
=={{header|J}}==
2,130

edits