Semiprime: Difference between revisions
Content added Content deleted
m (→{{header|Lambdatalk}}: minor edit) |
(→{{header|jq}}: simplify) |
||
Line 1,357: | Line 1,357: | ||
{{works with|jq}} |
{{works with|jq}} |
||
'''Works with gojq, the Go implementation of jq''' |
'''Works with gojq, the Go implementation of jq''' |
||
See e.g. [[Erd%C5%91s-primes#jq]] for a suitable implementation of `is_prime`. |
|||
<syntaxhighlight lang="jq"> |
<syntaxhighlight lang="jq"> |
||
# Output: a stream of proper factors (probably unsorted) |
|||
def proper_factors: |
|||
range(2; 1 + sqrt|floor) as $i |
|||
⚫ | |||
then (. / $i) as $r |
|||
⚫ | |||
⚫ | |||
⚫ | |||
def is_semiprime: |
def is_semiprime: |
||
{i: 2, n: ., nf: 0} |
|||
| until( .i > .n or .result; |
|||
| any(proper_factors; |
|||
until(.n % .i != 0 or .result; |
|||
if .nf == 2 then .result = 0 |
|||
⚫ | |||
| .n /= .i |
|||
⚫ | |||
⚫ | |||
⚫ | |||
</syntaxhighlight> |
</syntaxhighlight> |
||
'''Examples''' |
'''Examples''' |