Gaussian primes: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (More accurate teminology) |
(Realize in F#) |
||
Line 34: | Line 34: | ||
=={{header|F_Sharp|F#}}== |
|||
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)] |
|||
<lang fsharp> |
|||
// Gaussian primes. Nigel Galloway: July 29th., 2022 |
|||
let isGP=function (n,0)|(0,n)->let n=abs n in n%4=3 && isPrime n |(n,g)->isPrime(n*n+g*g) |
|||
Seq.allPairs [-9..9] [-9..9]|>Seq.filter isGP|>Seq.iter(fun(n,g)->printf $"""%d{n}%s{match g with 0->"" |g->sprintf $"%+d{g}i"} """); printfn "" |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
-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|J}}== |
=={{header|J}}== |
||
Implementation: <lang J>isgpri=: {{ |
Implementation: <lang J>isgpri=: {{ |