user
Definitions

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.

Examples

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

Task
:   :   * show the first   **35**   unprimeable numbers   (horizontally, on one line, preferably with a title)
        * show the   **600th**   unprimeable number
        * (optional) show the lowest unprimeable number ending in a specific decimal digit   (**0, 1, 2, 3, 4, 5, 6, 7, 8, 9**)
        * (optional) use commas in the numbers where appropriate

Show all output here, on this page.

Also see
:   * the     OEIS     entry:   A118118 (unprimeable)
    * with some useful counts to compare unprimeable number
    * the Wiktionary entry (reference from below):   (arithmetic definition) unprimeable
    * from the Adam Spencer book   (page 200):   *Adam Spencer's World of Numbers*       (Xoum Publishing)
assistant
(formerly Perl 6)

**Library:** ntheory

```
use ntheory:from<Perl5> <is_prime>;
use Lingua::EN::Numbers;

sub is-unprimeable (\n) {
     return False if n.&is_prime;
     my \chrs = n.chars;
     for ^chrs -> \place {
         my \pow = 10**(chrs - place - 1);
         my \this = n.substr(place, 1) × pow;
         ^10 .map: -> \dgt {
             next if this == dgt;
             return False if is_prime(n - this + dgt × pow)
         }
     }
     True
}

my @ups = lazy ^∞ .grep: { .&is-unprimeable };

say "First 35 unprimeables:\n" ~ @ups[^35];

say "\n{ordinal-digit(600, :u)} unprimeable: " ~ comma( @ups[599] ) ~ "\n";

^10 .map: -> \n {
    print "First unprimeable that ends with {n}: " ~
    sprintf "%9s\n", comma (n, *+10 … *).race.first: { .&is-unprimeable }
}

```

Output:

```
First 35 unprimeables:
200 204 206 208 320 322 324 325 326 328 510 512 514 515 516 518 530 532 534 535 536 538 620 622 624 625 626 628 840 842 844 845 846 848 890

600ᵗʰ unprimeable: 5,242

First unprimeable that ends with 0:       200
First unprimeable that ends with 1:   595,631
First unprimeable that ends with 2:       322
First unprimeable that ends with 3: 1,203,623
First unprimeable that ends with 4:       204
First unprimeable that ends with 5:       325
First unprimeable that ends with 6:       206
First unprimeable that ends with 7:   872,897
First unprimeable that ends with 8:       208
First unprimeable that ends with 9:   212,159
```