Gaussian primes: Difference between revisions

added RPL
m (→‎{{header|Wren}}: Changed to Wren S/H)
(added RPL)
 
(One intermediate revision by one other user not shown)
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}}==
Line 1,249 ⟶ 1,278:
 
Off-site SVG image: [https://raw.githubusercontent.com/thundergnat/rc/master/img/gaussian-primes-raku.svg gaussian-primes-raku.svg]
 
=={{header|RPL}}==
« → radius
« { }
1 radius '''FOR''' a
0 a '''FOR''' b
'''IF''' a SQ b SQ + radius SQ ≤ '''THEN'''
{ }
'''IF''' b '''THEN'''
'''IF''' a SQ b SQ + ISPRIME? '''THEN'''
a b R→C DUP CONJ OVER NEG DUP CONJ 4 →LIST +
'''END'''
'''ELSE'''
'''IF''' a ISPRIME? a 4 MOD 3 == AND '''THEN'''
a DUP NEG 2 →LIST +
'''END'''
'''END'''
'''IF''' DUP SIZE '''THEN '''
'''IF''' a b ≠ '''THEN''' DUP (0,1) * + '''END'''
+
'''ELSE''' DROP '''END'''
'''END'''
'''NEXT NEXT '''
» » '<span style="color:blue">GPRIMES</span>' STO
« 10 <span style="color:blue">GPRIMES</span>
(-50 -50) PMIN (50 50) PMAX ERASE
50 <span style="color:blue">GPRIMES</span> 1 « '''IF''' DUP IM NOT '''THEN''' 0 R→C '''END''' PIXON » DOLIST
{ } PVIEW
» '<span style="color:blue">TASK</span>' STO
[[File:Gaussian primes.png|thumb|alt=Gaussian primes within radius 50|HP-48G emulator screenshot]]
{{out}}
<pre>
1: { (1.,1.) (1.,-1.) (-1.,-1.) (-1.,1.) (2.,1.) (2.,-1.) (-2.,-1.) (-2.,1.) (-1.,2.) (1.,2.) (1.,-2.) (-1.,-2.) 3 -3 (0.,3.) (0.,-3.) (3.,2.) (3.,-2.) (-3.,-2.) (-3.,2.) (-2.,3.) (2.,3.) (2.,-3.) (-2.,-3.) (4.,1.) (4.,-1.) (-4.,-1.) (-4.,1.) (-1.,4.) (1.,4.) (1.,-4.) (-1.,-4.) (5.,2.) (5.,-2.) (-5.,-2.) (-5.,2.) (-2.,5.) (2.,5.) (2.,-5.) (-2.,-5.) (5.,4.) (5.,-4.) (-5.,-4.) (-5.,4.) (-4.,5.) (4.,5.) (4.,-5.) (-4.,-5.) (6.,1.) (6.,-1.) (-6.,-1.) (-6.,1.) (-1.,6.) (1.,6.) (1.,-6.) (-1.,-6.) (6.,5.) (6.,-5.) (-6.,-5.) (-6.,5.) (-5.,6.) (5.,6.) (5.,-6.) (-5.,-6.) 7 -7 (0.,7.) (0.,-7.) (7.,2.) (7.,-2.) (-7.,-2.) (-7.,2.) (-2.,7.) (2.,7.) (2.,-7.) (-2.,-7.) (8.,3.) (8.,-3.) (-8.,-3.) (-8.,3.) (-3.,8.) (3.,8.) (3.,-8.) (-3.,-8.) (8.,5.) (8.,-5.) (-8.,-5.) (-8.,5.) (-5.,8.) (5.,8.) (5.,-8.) (-5.,-8.) (9.,4.) (9.,-4.) (-9.,-4.) (-9.,4.) (-4.,9.) (4.,9.) (4.,-9.) (-4.,-9.) }
</pre>
 
=={{header|Wren}}==
1,150

edits