How to resolve the algorithm Ascending primes step by step in the Arturo programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Ascending primes step by step in the Arturo 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 Arturo programming language

Source code in the arturo programming language

ascending?: function [x][
    initial: digits x
    and? [equal? sort initial initial][equal? size initial size unique initial]
]

candidates: select (1..1456789) ++ [
    12345678, 12345679, 12345689, 12345789, 12346789,
    12356789, 12456789, 13456789, 23456789, 123456789 
] => prime?

ascendingNums: select candidates => ascending?

loop split.every:10 ascendingNums 'nums [
    print map nums 'num -> pad to :string num 10
]


  

You may also check:How to resolve the algorithm Successive prime differences step by step in the Picat programming language
You may also check:How to resolve the algorithm Topological sort step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Runge-Kutta method step by step in the AWK programming language
You may also check:How to resolve the algorithm Associative array/Iteration step by step in the ooRexx programming language
You may also check:How to resolve the algorithm Power set step by step in the C programming language