Honaker primes: Difference between revisions

m
julia example
m (use primes function)
m (julia example)
Line 277:
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}}==
<syntaxhighlight lang="julia">""" Rosetta code task: rosettacode.org/wiki/Honaker_primes """
 
using Formatting
using Primes
 
""" Get the sequence of Honaker primes as tuples with their primepi values first in tuple"""
honaker(N, lim) = [(i, p) for (i, p) in enumerate(primes(lim)) if sum(digits(p)) == sum(digits(i))]
 
println("First 50 Honaker primes:")
const a = honaker(10_000, 5_000_000)
foreach(p -> print(rpad(p[2], 12), p[1] % 5 == 0 ? "\n" : ""), enumerate(a[1:50]))
println("\n$(format(a[10000][2], commas = true)) is the ",
"$(format(a[10000][1], commas = true))th prime and the 10,000th Honaker prime.")
</syntaxhighlight>{{out}}
<pre>
First 50 Honaker primes:
(32, 131) (56, 263) (88, 457) (175, 1039) (176, 1049)
(182, 1091) (212, 1301) (218, 1361) (227, 1433) (248, 1571)
(293, 1913) (295, 1933) (323, 2141) (331, 2221) (338, 2273)
(362, 2441) (377, 2591) (386, 2663) (394, 2707) (397, 2719)
(398, 2729) (409, 2803) (439, 3067) (446, 3137) (457, 3229)
(481, 3433) (499, 3559) (508, 3631) (563, 4091) (571, 4153)
(595, 4357) (599, 4397) (635, 4703) (637, 4723) (655, 4903)
(671, 5009) (728, 5507) (751, 5701) (752, 5711) (755, 5741)
(761, 5801) (767, 5843) (779, 5927) (820, 6301) (821, 6311)
(826, 6343) (827, 6353) (847, 6553) (848, 6563) (857, 6653)
 
4,043,749 is the 286,069th prime and the 10,000th Honaker prime.
</pre>
 
=={{header|Phix}}==
4,105

edits