Gaussian primes: Difference between revisions

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

edits