Descending primes: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) m (→{{header|11l}}) |
|||
Line 586: | Line 586: | ||
76543 76541 76421 75431 764321 83 863 853 821 8761 8753 8741 8731 8641 8543 8521 8431 87643 87641 87631 87541 87421 86531 876431 865321 8765321 8764321 97 983 |
76543 76541 76421 75431 764321 83 863 853 821 8761 8753 8741 8731 8641 8543 8521 8431 87643 87641 87631 87541 87421 86531 876431 865321 8765321 8764321 97 983 |
||
971 953 941 9871 9851 9743 9721 9643 9631 9521 9431 9421 98731 98641 98621 98543 98321 97651 96431 94321 987631 987541 986543 975421 9875321 9754321 98765431 98764321 97654321</syntaxhighlight> |
971 953 941 9871 9851 9743 9721 9643 9631 9521 9431 9421 98731 98641 98621 98543 98321 97651 96431 94321 987631 987541 986543 975421 9875321 9754321 98765431 98764321 97654321</syntaxhighlight> |
||
=={{header|jq}}== |
|||
{{works with|jq}} |
|||
''Also works with gojq and fq'' provided _nwise/1 is defined as in jq. |
|||
'''Preliminaries''' |
|||
<syntaxhighlight lang=jq> |
|||
# Output: a stream of the powersets of the input array |
|||
def powersets: |
|||
if length == 0 then . |
|||
else .[-1] as $x |
|||
| .[:-1] | powersets |
|||
| ., . + [$x] |
|||
end; |
|||
def is_prime: |
|||
. as $n |
|||
| if ($n < 2) then false |
|||
elif ($n % 2 == 0) then $n == 2 |
|||
elif ($n % 3 == 0) then $n == 3 |
|||
elif ($n % 5 == 0) then $n == 5 |
|||
elif ($n % 7 == 0) then $n == 7 |
|||
elif ($n % 11 == 0) then $n == 11 |
|||
elif ($n % 13 == 0) then $n == 13 |
|||
elif ($n % 17 == 0) then $n == 17 |
|||
elif ($n % 19 == 0) then $n == 19 |
|||
else 23 |
|||
| until( (. * .) > $n or ($n % . == 0); .+2) |
|||
| . * . > $n |
|||
end; |
|||
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .; |
|||
</syntaxhighlight> |
|||
'''Descending primes''' |
|||
<syntaxhighlight lang=jq> |
|||
[range(9;0;-1)] |
|||
| [powersets |
|||
| map(tostring) |
|||
| join("") |
|||
| select(length > 0) |
|||
| tonumber |
|||
| select(is_prime)] |
|||
| sort |
|||
| _nwise(10) |
|||
| map(lpad(9)) |
|||
| join(" ") |
|||
</syntaxhighlight> |
|||
{{output}} |
|||
<pre> |
|||
2 3 5 7 31 41 43 53 61 71 |
|||
73 83 97 421 431 521 541 631 641 643 |
|||
653 743 751 761 821 853 863 941 953 971 |
|||
983 5431 6421 6521 7321 7541 7621 7643 8431 8521 |
|||
8543 8641 8731 8741 8753 8761 9421 9431 9521 9631 |
|||
9643 9721 9743 9851 9871 75431 76421 76541 76543 86531 |
|||
87421 87541 87631 87641 87643 94321 96431 97651 98321 98543 |
|||
98621 98641 98731 764321 865321 876431 975421 986543 987541 987631 |
|||
8764321 8765321 9754321 9875321 97654321 98764321 98765431 |
|||
</pre> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |