Honaker primes

Revision as of 01:46, 20 September 2022 by Thundergnat (talk | contribs) (New draft task and Raku example)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

A Honaker prime is a prime whose digital sum is equal to the digital sum of its position in the sequence of primes.

Honaker primes is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.


E.G.

If you look at the sequence of positive integer primes the first prime is 2 at position 1. The digital sums of 2 and 1 are not equal, so 2 is not a Honaker prime. The prime at position 32: 131 is a Honaker prime. The digital sum of 32 (5) is equal to the digital sum of 131 (5).


Task
  • Write a routine (procedure, function, filter, whatever it may be called in your language) to identify Honaker primes.
  • Use that routine to find the first fifty Honaker primes and display the position and value for each.


Stretch
  • Find and display the ten thousandth Honaker prime (position and value).


See also


Raku

my @honaker = lazy (^∞ .hyper.grep: &is-prime).kv.grep( 1 + *.comb.sum == *.comb.sum );

say "First 50 Honaker primes (index, prime):\n" ~ @honaker[^50].map(&format).batch(10).join: "\n";
say "Ten thousandth: " ~ @honaker[9999].&format;

sub format ($_) { sprintf "(%3d, %4d)", 1 + .[0], .[1] }
Output:
First 50 Honaker primes (index, prime):
( 32,  131) ( 56,  263) ( 70,  349) ( 88,  457) (130,  733) (175, 1039) (176, 1049) (182, 1091) (212, 1301) (218, 1361)
(227, 1433) (248, 1571) (293, 1913) (295, 1933) (320, 2129) (323, 2141) (331, 2221) (338, 2273) (350, 2357) (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) (760, 5791) (761, 5801) (767, 5843) (779, 5927) (821, 6311) (826, 6343)
Ten thousandth: (266396, 3745229)