Generate and show all primes with strictly descending decimal digits.

See also
 OEIS:A052014 - Primes with distinct digits in descending order
Related

Ascending primes


func primes_with_descending_digits(base = 10) {
 
    var list = []
    var digits = @(1..^base)
 
    var end_digits = digits.grep { .is_coprime(base) }
    list << digits.grep { .is_prime && !.is_coprime(base) }...
 
    for k in (0 .. digits.end) {
        digits.combinations(k, {|*a|
            var v = a.digits2num(base)
            end_digits.each {|d|
                var n = (v*base + d)
                next if ((n >= base) && (a[0] <= d))
                list << n if n.is_prime
            }
        })
    }
 
    list.sort
}
 
var base = 10
var arr = primes_with_descending_digits(base)
 
say "There are #{arr.len} descending primes in base #{base}.\n"
 
arr.each_slice(8, {|*a|
    say a.map { '%9s' % _ }.join(' ')
})