How to resolve the algorithm Unprimeable numbers step by step in the J programming language
How to resolve the algorithm Unprimeable numbers step by step in the J 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 J programming language
Source code in the j programming language
NB. replace concatenates at various ranks and in boxes to avoid fill
NB. the curtailed prefixes (}:\) with all of 0..9 (i.10) with the beheaded suffixes (}.\.)
NB. under the antibase 10 representation (10&#.inv)
replace=: ([: ; <@}:\ ,"1 L:_1 ([: < (i.10) ,"0 1 }.)\.)&.(10&#.inv)
NB. primable tests if one of the replacements is prime
primable=: (1 e. 1 p: replace)&>
unprimable=: -.@:primable
assert 0 1 -: unprimable 193 200
You may also check:How to resolve the algorithm Prime decomposition step by step in the Racket programming language
You may also check:How to resolve the algorithm Anagrams step by step in the Raku programming language
You may also check:How to resolve the algorithm Bulls and cows step by step in the jq programming language
You may also check:How to resolve the algorithm Digital root step by step in the S-BASIC programming language
You may also check:How to resolve the algorithm Bitwise IO step by step in the Python programming language