How to resolve the algorithm Unprimeable numbers step by step in the Arturo programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Unprimeable numbers step by step in the Arturo programming language

Table of Contents

Problem Statement

As used here, all unprimeable numbers   (positive integers)   are always expressed in base ten.

───── Definition from OEIS ─────: Unprimeable numbers are composite numbers that always remain composite when a single decimal digit of the number is changed.

───── Definition from Wiktionary   (referenced from Adam Spencer's book) ─────: (arithmetic)   that cannot be turned into a prime number by changing just one of its digits to any other digit.   (sic)

Unprimeable numbers are also spelled:   unprimable. All one─ and two─digit numbers can be turned into primes by changing a single decimal digit.

190   isn't unprimeable,   because by changing the zero digit into a three yields   193,   which is a prime.

The number   200   is unprimeable,   since none of the numbers   201, 202, 203, ··· 209   are prime, and all the other numbers obtained by changing a single digit to produce   100, 300, 400, ··· 900,   or   210, 220, 230, ··· 290   which are all even.

It is valid to change   189   into   089   by changing the   1   (one)   into a   0   (zero),   which then the leading zero can be removed,   and then treated as if the   "new"   number is   89.

Show all output here, on this page.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Unprimeable numbers step by step in the Arturo programming language

Source code in the arturo programming language

unprimeable?: function [n][
    if prime? n -> return false
    nd: to :string n
    loop.with:'i nd 'prevDigit [
        loop `0`..`9` 'newDigit [
            if newDigit <> prevDigit [
                nd\[i]: newDigit
                if prime? to :integer nd -> return false
            ]
        ]
        nd\[i]: prevDigit
    ]
    return true
]

cnt: 0
x: 1
unprimeables: []
while [cnt < 600][
    if unprimeable? x [
        unprimeables: unprimeables ++ x
        cnt: cnt + 1
    ]
    x: x + 1
]

print "First 35 unprimeable numbers:"
print first.n: 35 unprimeables
print ""
print ["600th unprimeable number:" last unprimeables]


  

You may also check:How to resolve the algorithm Price fraction step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Pseudo-random numbers/Xorshift star step by step in the Perl programming language
You may also check:How to resolve the algorithm Perfect totient numbers step by step in the Dart programming language
You may also check:How to resolve the algorithm Kolakoski sequence step by step in the Lua programming language
You may also check:How to resolve the algorithm String concatenation step by step in the Golfscript programming language