Unprimeable numbers

func is_unprimeable(n) {
    var t = 10*floor(n/10)
    for k in (t+1 .. t+9 `by` 2) {
        return false if k.is_prime
    }

    if (n.is_div(2) || n.is_div(5)) {
        return true if !is_prime(n%10)
        return true if (n % 10**n.ilog(10) > 9)
    }

    for k in (1 .. n.ilog(10)) {
        var u = 10**k
        var v = (n - (u * (floor(n/u) % 10)))
        0..9 -> any {|d| is_prime(v + d*u) } && return false
    }

    return true
}

with (35) {|n|
    say ("First #{n} unprimeables:\n", is_unprimeable.first(n).join(' '))
}

with (600) {|n|
    say ("\n#{n}th unprimeable: ", is_unprimeable.nth(n), "\n")
}

for d in (0..9) {
    say ("First unprimeable that ends with #{d}: ",
        1..Inf -> lazy.map {|k| k*10 + d }.grep(is_unprimeable).first)
}

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

600th unprimeable: 5242

First unprimeable that ends with 0: 200
First unprimeable that ends with 1: 595631
First unprimeable that ends with 2: 322
First unprimeable that ends with 3: 1203623
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: 872897
First unprimeable that ends with 8: 208
First unprimeable that ends with 9: 212159

Last updated