Sum of square and cube digits of an integer are primes: Difference between revisions
Content added Content deleted
(→OCaml: add) |
(jq) |
||
Line 395: | Line 395: | ||
{{out}} |
{{out}} |
||
<pre>16 17 25 28 34 37 47 52 64</pre> |
<pre>16 17 25 28 34 37 47 52 64</pre> |
||
=={{header|jq}}== |
|||
{{works with|jq}} |
|||
''Also works with gojq and fq'' |
|||
'''Preliminaries''' |
|||
<syntaxhighlight lang=jq> |
|||
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 digitSum: tostring | explode | map([.] | implode | tonumber) | add; |
|||
</syntaxhighlight> |
|||
'''The Task''' |
|||
<syntaxhighlight lang=jq> |
|||
range(1;100) |
|||
| (.*.) as $sq |
|||
| select( ($sq | digitSum | is_prime) and ($sq * . | digitSum | is_prime ) ) |
|||
</syntaxhighlight> |
|||
{{output}} |
|||
<pre> |
|||
16 |
|||
17 |
|||
25 |
|||
28 |
|||
34 |
|||
37 |
|||
47 |
|||
52 |
|||
64 |
|||
</pre> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |