Honaker primes

From Rosetta Code
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.

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


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


ALGOL 68[edit]

After experimenting on TIO.RUN, it seems that with ALGOL 68G, calculating the digit sums the "traditional" way is slightly faster than generating a table of digit sums. In the sample below, the digit sum is calculated by first converting the number to a string - this is faster in ALGOL 68G than using MOD and division. For other implementations of Algol 68, using MOD and division may be faster.

BEGIN # find some Honaker primes: primes whose digit-sum equals the   #
      # digit-sum of the index of the prime in the list of primes     #
      # e.g.: prime 32 (dsum 5) = 131 (dsum 5)                        #
    INT h count    :=  0; # number of Honaker primes found so far     #
    # sieve the primes up to 5 000 000, hopefully enough...           #
    [ 0 : 5 000 000 ]BOOL prime;
    prime[ 0 ] := prime[ 1 ] := FALSE;
    prime[ 2 ] := TRUE;
    FOR i FROM 3 BY 2 TO UPB prime DO prime[ i ] := TRUE  OD;
    FOR i FROM 4 BY 2 TO UPB prime DO prime[ i ] := FALSE OD;
    FOR i FROM 3 BY 2 TO ENTIER sqrt( UPB prime ) DO
        IF prime[ i ] THEN
            FOR s FROM i * i BY i + i TO UPB prime DO prime[ s ] := FALSE OD
        FI
    OD;
    # returns the digit sum of n                                       #
    PROC dsum = ( INT n )INT:
         BEGIN
            INT    sum := 0;
            STRING s    = whole( n, 0 );
            FOR s pos FROM LWB s TO UPB s DO
                sum +:= ABS s[ s pos ] - ABS "0"
            OD;
            sum
         END # digit sum # ;
    # attempt to find the Honaker primes                               #
    INT p count := 0;
    FOR n FROM LWB prime TO UPB prime DO
        IF prime[ n ] THEN
            # have the p count'th prime                                #
            p count +:= 1;
            IF dsum( n ) = dsum( p count ) THEN
                # have a Honaker prime                                 #
                IF ( h count +:= 1 ) < 51 THEN
                    print( ( "(",  whole( h count, -2 )
                           , ": ", whole( p count, -3 )
                           , " ",  whole( n,       -4 )
                           , ") "
                           )
                         );
                    IF h count MOD 5 = 0 THEN print( ( newline ) ) FI
                ELIF h count = 10 000 THEN
                    print( ( newline
                           , "Honaker prime ", whole( h count, 0 )
                           , " is prime ",     whole( p count, 0 )
                           , ": ",             whole( n,       0 )
                           , newline
                           )
                         )
                FI
            FI
        FI
    OD
END
Output:
( 1:  32  131) ( 2:  56  263) ( 3:  88  457) ( 4: 175 1039) ( 5: 176 1049)
( 6: 182 1091) ( 7: 212 1301) ( 8: 218 1361) ( 9: 227 1433) (10: 248 1571)
(11: 293 1913) (12: 295 1933) (13: 323 2141) (14: 331 2221) (15: 338 2273)
(16: 362 2441) (17: 377 2591) (18: 386 2663) (19: 394 2707) (20: 397 2719)
(21: 398 2729) (22: 409 2803) (23: 439 3067) (24: 446 3137) (25: 457 3229)
(26: 481 3433) (27: 499 3559) (28: 508 3631) (29: 563 4091) (30: 571 4153)
(31: 595 4357) (32: 599 4397) (33: 635 4703) (34: 637 4723) (35: 655 4903)
(36: 671 5009) (37: 728 5507) (38: 751 5701) (39: 752 5711) (40: 755 5741)
(41: 761 5801) (42: 767 5843) (43: 779 5927) (44: 820 6301) (45: 821 6311)
(46: 826 6343) (47: 827 6353) (48: 847 6553) (49: 848 6563) (50: 857 6653)

Honaker prime 10000 is prime 286069: 4043749

C++[edit]

Library: Primesieve
#include <iomanip>
#include <iostream>
#include <sstream>
#include <utility>

#include <primesieve.hpp>

uint64_t digit_sum(uint64_t n) {
    uint64_t sum = 0;
    for (; n > 0; n /= 10)
        sum += n % 10;
    return sum;
}

class honaker_prime_generator {
public:
    std::pair<uint64_t, uint64_t> next();

private:
    primesieve::iterator pi_;
    uint64_t index_ = 0;
};

std::pair<uint64_t, uint64_t> honaker_prime_generator::next() {
    for (;;) {
        uint64_t prime = pi_.next_prime();
        ++index_;
        if (digit_sum(index_) == digit_sum(prime))
            return std::make_pair(index_, prime);
    }
}

std::ostream& operator<<(std::ostream& os,
                         const std::pair<uint64_t, uint64_t>& p) {
    std::ostringstream str;
    str << '(' << p.first << ", " << p.second << ')';
    return os << str.str();
}

int main() {
    honaker_prime_generator hpg;
    std::cout << "First 50 Honaker primes (index, prime):\n";
    int i = 1;
    for (; i <= 50; ++i)
        std::cout << std::setw(11) << hpg.next() << (i % 5 == 0 ? '\n' : ' ');
    for (; i < 10000; ++i)
        hpg.next();
    std::cout << "\nTen thousandth: " << hpg.next() << '\n';
}
Output:
First 50 Honaker primes (index, prime):
  (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)

Ten thousandth: (286069, 4043749)

F#[edit]

This task uses Extensible Prime Generator (F#)

// Honaker primes. Nigel Galloway: September 21st., 2022
let rec fG n g=if n<10 then n+g else fG(n/10)(g+n%10)
let Honaker()=primes32()|>Seq.mapi(fun n g->(n+1,g,fG g 0,fG (n+1) 0))|>Seq.choose(fun(i,g,e,l)->if e=l then Some(i,g) else None)
Honaker()|>Seq.chunkBySize 10|>Seq.take 5|>Seq.iter(fun g->g|>Seq.iter(printf "%A "); printfn "")
printfn "%A" (Seq.item 9999 (Honaker()))
Output:
(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)

(286069, 4043749)

Factor[edit]

Works with: Factor version 0.99 2022-04-03
USING: grouping kernel lists lists.lazy math math.primes.lists
prettyprint sequences ;

: sum-digits ( n -- sum )
    0 swap [ 10 /mod rot + swap ] until-zero ;

: honaker ( -- list )
    1 lfrom lprimes lzip [ first2 [ sum-digits ] same? ] lfilter ;

50 honaker ltake list>array 5 group simple-table.
Output:
{ 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 }

FreeBASIC[edit]

' version 20-09-2022
' compile with: fbc -s console

Function dig_sum(n As UInteger) As UInteger

    Dim As UInteger sum

    While n > 0
        sum += n Mod 10
        n \= 10
    Wend

    Return sum

End Function

' ------=< MAIN >=------

#Define max 5 * 10^6

Dim As UInteger x, y, place, rank = 1
Dim Shared As UInteger prime(max)

For x = 3 To max Step 2
    If prime(x) = 0 Then
        For y = x * x To max Step x + x
            prime(y) = 1
        Next
    End If
Next

For x = 3 To max Step 2
    If prime(x) = 0 Then
        rank += 1
        If rank Mod 9 = x Mod 9 Then
            If dig_sum(rank) = dig_sum(x) Then
                place += 1
                If place <= 50 Then
                    Print Using "   ##: ### #####"; place ; rank ; x;
                    If (place Mod 5) = 0 Then Print
                End If
                If place = 10000 Then
                    Print
                    Print "   10000th honaker prime is at ";rank; " and is ";x
                End If
            End If
        End If
    End If
Next


' empty keyboard buffer
While Inkey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End
Output:
    1:  32   131    2:  56   263    3:  88   457    4: 175  1039    5: 176  1049
    6: 182  1091    7: 212  1301    8: 218  1361    9: 227  1433   10: 248  1571
   11: 293  1913   12: 295  1933   13: 323  2141   14: 331  2221   15: 338  2273
   16: 362  2441   17: 377  2591   18: 386  2663   19: 394  2707   20: 397  2719
   21: 398  2729   22: 409  2803   23: 439  3067   24: 446  3137   25: 457  3229
   26: 481  3433   27: 499  3559   28: 508  3631   29: 563  4091   30: 571  4153
   31: 595  4357   32: 599  4397   33: 635  4703   34: 637  4723   35: 655  4903
   36: 671  5009   37: 728  5507   38: 751  5701   39: 752  5711   40: 755  5741
   41: 761  5801   42: 767  5843   43: 779  5927   44: 820  6301   45: 821  6311
   46: 826  6343   47: 827  6353   48: 847  6553   49: 848  6563   50: 857  6653

   10000th honaker prime is at 286069 and is 4043749

Haskell[edit]

import Control.Monad (join)
import Data.Bifunctor (bimap)
import Data.List.Split (chunksOf)
import Data.Numbers.Primes (primes)

---------------------- HONAKER PRIMES --------------------

honakers :: [(Integer, Integer)]
honakers =
  filter
    (uncurry (==) . both sumDigits)
    (zip [1 ..] primes)

--------------------------- TEST -------------------------
main :: IO ()
main = do
  putStrLn "First Fifty:\n"
  mapM_ (putStrLn . unwords) $
    chunksOf 5 $
      take 50 (show <$> honakers)
      
  putStrLn "\n10Kth:\n"
  print $ honakers !! pred 10000

------------------------- GENERIC ------------------------
sumDigits :: Integer -> Integer
sumDigits = foldr ((+) . read . return) 0 . show

both :: (a -> b) -> (a, a) -> (b, b)
both = join bimap
Output:
First Fifty:

(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)

10Kth:

(286069,4043749)

J[edit]

Implementation:

honk=: >: =&(+/@(10&#.inv))"0 p:

This tests a sequence of prime indices to determine whether the corresponding prime is a honaker prime. Here, >: adds 1 (since J indices start with 0 and Honaker prime indices start with 1). Also, p: yields the prime for an index, and +/@(10&#.inv) computes a digital sum of a number (but not a sequence, so we use "0 to map it onto sequences). So, =&(+/@(10&#.inv))"0 identifies members of a pair of sequences (one on the left, the other on the right) whose digital sums match.

Task example:
   (>: j. p:) 5 10$I.honk i.1e3
  32j131   56j263   88j457 175j1039 176j1049 182j1091 212j1301 218j1361 227j1433 248j1571
293j1913 295j1933 323j2141 331j2221 338j2273 362j2441 377j2591 386j2663 394j2707 397j2719
398j2729 409j2803 439j3067 446j3137 457j3229 481j3433 499j3559 508j3631 563j4091 571j4153
595j4357 599j4397 635j4703 637j4723 655j4903 671j5009 728j5507 751j5701 752j5711 755j5741
761j5801 767j5843 779j5927 820j6301 821j6311 826j6343 827j6353 847j6553 848j6563 857j6653

Here, we test the first thousand primes to see which are prime indices of Honaker primes. Then I.converts the test results back to index form, and 5 10$I. 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.

Julia[edit]

""" 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(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(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.")
Output:
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.

Perl[edit]

Library: ntheory
use v5.36;
use ntheory 'nth_prime';
use List::Util <max sum>;

sub table ($c, @V) { my $t = $c * (my $w = 2 + max map { length } @V); ( sprintf( ('%'.$w.'s')x@V, @V) ) =~ s/.{1,$t}\K/\n/gr }
sub comma { scalar reverse join ',', unpack '(A3)*', reverse shift }

my($n,@honaker);

while () {
    my $p = nth_prime(++$n);
    push @honaker, [$n, $p] if (sum split '', $p) == sum split '', $n;
    last if 10_000 == @honaker;
}

push @res, "First 50 Honaker primes (index, prime):";
push @res, table 5, map { sprintf "(%3d, %4d)", @$_ } @honaker[0..49];

push @res, "Ten thousandth: " . sprintf "(%s, %s)", map { comma $_ } @{$honaker[9999]};
Output:
First 50 Honaker primes (index, prime):
  ( 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)

Ten thousandth: (286,069, 4,043,749)

Phix[edit]

with javascript_semantics

function digital_sum(integer i)
    integer res = 0
    while i do
        res += remainder(i,10)
        i = floor(i/10)
    end while
    return res
end function

sequence res = {}
integer pdx = 1, p
while length(res)<10_000 do
    p = get_prime(pdx)
    if digital_sum(p)=digital_sum(pdx) then
        res = append(res,{pdx,p})
    end if
    pdx += 1
end while
string r = join_by(apply(true,sprintf,{{"(%3d,%4d)"},res[1..50]}),1,10," ")
printf(1,"First 50 Honaker primes (index, prime):\n%s\n",{r})
{pdx,p} = res[10000]
printf(1,"The %,d%s prime is %,d which is the 10,000th Honaker prime\n",{pdx,ord(pdx),p})
Output:
First 50 Honaker primes (index, prime):
( 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)

The 286,069th prime is 4,043,749 which is the 10,000th Honaker prime

Python[edit]

''' Rosetta code task: rosettacode.org/wiki/Honaker_primes '''


from pyprimesieve import primes


def digitsum(num):
    ''' Digit sum of an integer (base 10) '''
    return sum(int(c) for c in str(num))


def generate_honaker(limit=5_000_000):
    ''' Generate the sequence of Honaker primes with their sequence and primepi values '''
    honaker = [(i + 1, p) for i, p in enumerate(primes(limit)) if digitsum(p) == digitsum(i + 1)]
    for hcount, (ppi, pri) in enumerate(honaker):
        yield hcount + 1, ppi, pri


print('First 50 Honaker primes:')
for p in generate_honaker():
    if p[0] < 51:
        print(f'{str(p):16}', end='\n' if p[0] % 5 == 0 else '')
    elif p[0] == 10_000:
        print(f'\nThe 10,000th Honaker prime is the {p[1]:,}th one, which is {p[2]:,}.')
        break
Output:
First 50 Honaker primes:
(1, 32, 131)    (2, 56, 263)    (3, 88, 457)    (4, 175, 1039)  (5, 176, 1049)  
(6, 182, 1091)  (7, 212, 1301)  (8, 218, 1361)  (9, 227, 1433)  (10, 248, 1571) 
(11, 293, 1913) (12, 295, 1933) (13, 323, 2141) (14, 331, 2221) (15, 338, 2273) 
(16, 362, 2441) (17, 377, 2591) (18, 386, 2663) (19, 394, 2707) (20, 397, 2719) 
(21, 398, 2729) (22, 409, 2803) (23, 439, 3067) (24, 446, 3137) (25, 457, 3229) 
(26, 481, 3433) (27, 499, 3559) (28, 508, 3631) (29, 563, 4091) (30, 571, 4153) 
(31, 595, 4357) (32, 599, 4397) (33, 635, 4703) (34, 637, 4723) (35, 655, 4903) 
(36, 671, 5009) (37, 728, 5507) (38, 751, 5701) (39, 752, 5711) (40, 755, 5741) 
(41, 761, 5801) (42, 767, 5843) (43, 779, 5927) (44, 820, 6301) (45, 821, 6311) 
(46, 826, 6343) (47, 827, 6353) (48, 847, 6553) (49, 848, 6563) (50, 857, 6653) 

The 10,000th Honaker prime is the 286,069th one, which is 4,043,749.


Or, a variant, without importing a primes function:

'''Honaker primes'''

from itertools import chain, count, islice
from functools import reduce


def honakers():
    '''Infinite stream of Honaker terms,
       tupled with their 1-based indices.
    '''
    def f(ip):
        return [ip] if (
            digitSum(ip[0]) == digitSum(ip[1])
        ) else []

    return chain.from_iterable(
        map(f, zip(count(1), primes()))
    )


# digitSum :: Int -> Int
def digitSum(n):
    '''Sum of the decimal digits of the given integer.
    '''
    return reduce(
        lambda a, c: a + int(c),
        str(n),
        0
    )


# ------------------------- TEST -------------------------
# main :: IO ()
def main():
    '''Test'''
    print("First 50:\n")
    for xs in (
        chunksOf(5)(
            list(
                islice(
                    honakers(),
                    50
                )
            )
        )
    ):
        print(" ".join(repr(x) for x in xs))

    print("\n10Kth:\n")
    print(
        next(islice(honakers(), 10000-1, None))
    )


# ----------------------- GENERIC ------------------------

# chunksOf :: Int -> [a] -> [[a]]
def chunksOf(n):
    '''A series of lists of length n, subdividing the
       contents of xs. Where the length of xs is not evenly
       divisible, the final list will be shorter than n.
    '''
    def go(xs):
        return (
            xs[i:n + i] for i in range(0, len(xs), n)
        ) if 0 < n else None
    return go


# primes :: [Int]
def primes():
    '''An infinite stream of primes.
    '''
    seen = {}
    p = None
    yield 2
    for q in count(3, 2):
        p = seen.pop(q, None)
        if p is None:
            seen[q ** 2] = q
            yield q
        else:
            seen[
                until(lambda x: x not in seen)(
                    lambda x: x + 2 * p
                )(q + 2 * p)
            ] = p


# until :: (a -> Bool) -> (a -> a) -> a -> a
def until(p):
    '''The result of repeatedly applying f until p holds.
       The initial seed value is x.
    '''
    def go(f):
        def g(x):
            v = x
            while not p(v):
                v = f(v)
            return v
        return g
    return go


# MAIN ---
if __name__ == '__main__':
    main()
Output:
First 50:

(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)

10Kth:

(286069, 4043749)

Raku[edit]

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(5).join: "\n";
say "\nTen thousandth: " ~ @honaker[9999].&format;

sub format ($_) { sprintf "(%3d, %4d)", 1 + .[0], .[1] }
Output:
First 50 Honaker primes (index, prime):
( 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)

Ten thousandth: (286069, 4043749)

Wren[edit]

Library: Wren-math
Library: Wren-fmt
import "./math" for Int
import "./fmt" for Fmt

var primes = Int.primeSieve(5 * 1e6)
var i = 1
var count = 0
var h = []
var h10000
while (true) {
    if (Int.digitSum(i) == Int.digitSum(primes[i-1])) {
        count = count + 1
        if (count <= 50) {
            h.add([i, primes[i-1]])
        } else  if (count == 10000) {
            h10000 = [i, primes[i-1]]
            break
        }
    }
    i = i + 1
}
System.print("The first 50 Honecker primes (index, prime):")
for (i in 0..49) {
    Fmt.write("($3d, $,5d) ", h[i][0], h[i][1])
    if ((i + 1) % 5 == 0) System.print()
}
Fmt.print("\nand the 10,000th: ($,7d, $,9d)", h10000[0], h10000[1])
Output:
The first 50 Honecker primes (index, prime):
( 32,   131) ( 56,   263) ( 88,   457) (175, 1,039) (176, 1,049) 
(182, 1,091) (212, 1,301) (218, 1,361) (227, 1,433) (248, 1,571) 
(293, 1,913) (295, 1,933) (323, 2,141) (331, 2,221) (338, 2,273) 
(362, 2,441) (377, 2,591) (386, 2,663) (394, 2,707) (397, 2,719) 
(398, 2,729) (409, 2,803) (439, 3,067) (446, 3,137) (457, 3,229) 
(481, 3,433) (499, 3,559) (508, 3,631) (563, 4,091) (571, 4,153) 
(595, 4,357) (599, 4,397) (635, 4,703) (637, 4,723) (655, 4,903) 
(671, 5,009) (728, 5,507) (751, 5,701) (752, 5,711) (755, 5,741) 
(761, 5,801) (767, 5,843) (779, 5,927) (820, 6,301) (821, 6,311) 
(826, 6,343) (827, 6,353) (847, 6,553) (848, 6,563) (857, 6,653) 

and the 10,000th: (286,069, 4,043,749)

XPL0[edit]

func IsPrime(N);        \Return 'true' if N is prime
int  N, I;
[if N <= 2 then return N = 2;
if (N&1) = 0 then \even >2\ return false;
for I:= 3 to sqrt(N) do
    [if rem(N/I) = 0 then return false;
    I:= I+1;
    ];
return true;
];

func DigSum(N);         \Return sum of digits in N
int  N, S;
[S:= 0;
while N do
    [N:= N/10;
    S:= S + rem(0);
    ];
return S;
];

int N, C, H;
[Format(5, 0);
N:= 3;  C:= 1;  H:= 0;
loop    [if IsPrime(N) then
            [C:= C+1;
            if DigSum(N) = DigSum(C) then
                [H:= H+1;
                if H<=50 or H=10000 then
                    [RlOut(0, float(C));
                    Text(0, ": ");
                    RlOut(0, float(N));
                    if rem(H/5) = 0 then CrLf(0) else Text(0, "  ");
                    if H = 10000 then quit;
                    ];
                ];
            ];
        N:= N+2;
        ];
]
Output:
   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
286069: 4043749

Yabasic[edit]

Translation of: FreeBASIC
// Rosetta Code problem: http://rosettacode.org/wiki/Honaker_primes
// by Jjuanhdez, 09/2022

limit = 5 * 10^6
//place = 0
rank = 1
dim prime(limit)

for x = 3 to limit step 2
	if prime(x) = 0 then
		for y = x * x to limit step x + x
			prime(y) = 1
		next y
	end if
next x

print "First 50 Honaker primes:"
for x = 3 to limit step 2
	if prime(x) = 0 then
		rank = rank + 1
		if mod(rank, 9) = mod(x, 9) then
			if dig_sum(rank) = dig_sum(x) then
				place = place + 1
				if place <= 50 then
					print "  ", place using("##"), ": (", rank using("###"), ",", x using("#####"), ")";
					if mod(place, 5) = 0  print
				end if
				if place = 10000  print "\n  10000th honaker prime is at ", rank, " and is ", x
			end if
		end if
	end if
next x

sub dig_sum(n)
	local sum

	while n > 0
		sum = sum + mod(n, 10)
		n = int(n / 10)
	end while

	return sum
end sub
Output:
Same as FreeBASIC entry.