Gaussian primes: Difference between revisions

Content added Content deleted
(→‎{{header|jq}}: rm extraneous comment)
(→‎{{header|jq}}: streamline GPrimes)
Line 236: Line 236:
# emit a stream of Gaussian primes with real and imaginary parts within the given radius
# emit a stream of Gaussian primes with real and imaginary parts within the given radius
def GPrimes($Radius):
def GPrimes($Radius):
def check: abs | isPrime and ((. - 3) % 4 == 0);
($Radius | norm) as $R2
($Radius | norm) as $R2
| range(-$Radius; $Radius + 1) as $r
| range(-$Radius; $Radius + 1) as $r
| range(-$Radius; $Radius + 1) as $i
| range(-$Radius; $Radius + 1) as $i
| select( [$r,$i] | norm < $R2 )
| [$r, $i]
| if $i == 0
| norm as $norm
then ($r|abs) as $m
| select( $norm < $R2 )
| select( ($m|isPrime) and ($m - 3) % 4 == 0 ) | [$r,0]
| if $i == 0 then select($r|check)
elif $r == 0
elif $r == 0 then select($i|check)
else select($norm|isPrime)
then ($i|abs) as $m
| select( $m|isPrime and ($m - 3) % 4 == 0 ) | [0, $i]
else [$r, $i] | select(norm | isPrime)
end ;
end ;