Anaprimes: Difference between revisions

→‎{{header|J}}: add a "longest" variant
m (→‎{{header|J}}: quicky documentation)
(→‎{{header|J}}: add a "longest" variant)
Line 234:
largest=: 0 {:: big</syntaxhighlight>
 
Here, <code>dgt</code> gives use the base 10 digits of a number, <code>dgrp</code> groups numbers which contain the same digits, <code>pgrp</code> groups all primes of a given digit count by their digits, <code>big</code> sorts groups of numbers in descending order by their sum and <code>largest</code> extracts a group of numbers with the largest sum.
 
With these definitions, the count, min and max of prime groups with various (base 10) digit lengths are:
Line 256:
(#,<./,>./) largest pgrp 9
26455 103456789 987654103</syntaxhighlight>
 
Note that we could instead look for a longest group, where length is defined as the count of the primes in a group. That would give us:
 
<syntaxhighlight lang=J> longest=: 0 {:: (\: #@>)
(#,<./,>./) longest pgrp 1
1 7 7
(#,<./,>./) longest pgrp 2
2 79 97
(#,<./,>./) longest pgrp 3
4 179 971
(#,<./,>./) longest pgrp 4
11 1279 9721
(#,<./,>./) longest pgrp 5
39 13789 98731
(#,<./,>./) longest pgrp 6
148 123479 974213
(#,<./,>./) longest pgrp 7
731 1235789 9875321
(#,<./,>./) longest pgrp 8
4333 12345769 97654321
(#,<./,>./) longest pgrp 9
26519 102345697 976542103</syntaxhighlight>
 
=={{header|jq}}==
6,962

edits