Honaker primes: Difference between revisions

m
(Added Perl)
Line 335:
Implementation:
<syntaxhighlight lang=J>honk=: >: =&(+/@(10&#.inv))"0 p:</syntaxhighlight>
This tests a sequence of prime indices to determine whether the corresponding prime is a honaker prime. Here, <code>>:</code> adds 1 (since J indices start with 0 and Honaker prime indices start with 1). Also, <code>p:</code> yields the prime for an index, and <code>+/@(10&#.inv)</code> computes a digital sum of a number (but not a sequence, so we use <code>"0</code> to map it onto sequences). So, <code>=&(+/@(10&#.inv))"0</code> identifies members of a pair of sequences (one on the left, the other on the right) whose digital primessums match.
Task example:<syntaxhighlight lang=J> (>: j. p:) 5 10$I.honk i.1e3
32j131 56j263 88j457 175j1039 176j1049 182j1091 212j1301 218j1361 227j1433 248j1571
Line 343:
761j5801 767j5843 779j5927 820j6301 821j6311 826j6343 827j6353 847j6553 848j6563 857j6653</syntaxhighlight>
Here, we test the first thousand primes to see which are prime indices of Honaker primes. Then <code>I.</code>converts the test results back to index form, and <code>5 10$I.</code> organizes those indices in 5 rows of 10 columns (discarding any extra). Finally, we use complex number notation to form pairs of the corresponding honaker index and prime.
 
 
=={{header|Julia}}==
6,962

edits