How to resolve the algorithm Ascending primes step by step in the Perl programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Ascending primes step by step in the Perl programming language
Table of Contents
Problem Statement
Generate and show all primes with strictly ascending decimal digits. Aside: Try solving without peeking at existing solutions. I had a weird idea for generating a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial but generating them quickly is at least mildly interesting. Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is at least one significantly better and much faster way, needing a mere 511 odd/prime tests.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Ascending primes step by step in the Perl programming language
Source code in the perl programming language
use strict;
use warnings;
use ntheory 'is_prime';
print join( '',
map { sprintf '%10d', $_ }
sort { $a <=> $b }
grep /./ && is_prime $_,
glob join '', map "{$_,}", 1..9
) =~ s/.{50}\K/\n/gr;
You may also check:How to resolve the algorithm Average loop length step by step in the FutureBasic programming language
You may also check:How to resolve the algorithm Keyboard input/Obtain a Y or N response step by step in the Clojure programming language
You may also check:How to resolve the algorithm Maze generation step by step in the SuperCollider programming language
You may also check:How to resolve the algorithm 99 bottles of beer step by step in the Elan programming language
You may also check:How to resolve the algorithm LZW compression step by step in the Fortran programming language