How to resolve the algorithm Honaker primes step by step in the Arturo programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Honaker primes step by step in the Arturo programming language

Table of Contents

Problem Statement

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

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

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Honaker primes step by step in the Arturo programming language

Source code in the arturo programming language

honaker?: function [n, pos]->
    equal? sum digits n sum digits pos

idx: 0
found: 0

honakers: []

loop 2..'n [
    if prime? n [
        idx: idx + 1

        if honaker? n idx [
            found: found + 1
            'honakers ++ @[@[found, idx, n]]
        ]
    ]
    if found = 50 -> break
]

loop split.every: 5 honakers 'x ->
    print map x 's -> pad as.code s 14


  

You may also check:How to resolve the algorithm Deal cards for FreeCell step by step in the Python programming language
You may also check:How to resolve the algorithm Quad-power prime seeds step by step in the C programming language
You may also check:How to resolve the algorithm Additive primes step by step in the BCPL programming language
You may also check:How to resolve the algorithm Keyboard input/Keypress check step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Look-and-say sequence step by step in the Draco programming language