How to resolve the algorithm Smarandache prime-digital sequence step by step in the Raku programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Smarandache prime-digital sequence step by step in the Raku programming language

Table of Contents

Problem Statement

The Smarandache prime-digital sequence (SPDS for brevity) is the sequence of primes whose digits are themselves prime. For example 257 is an element of this sequence because it is prime itself and its digits: 2, 5 and 7 are also prime.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Smarandache prime-digital sequence step by step in the Raku programming language

Source code in the raku programming language

use Lingua::EN::Numbers;
use ntheory:from <:all>;

# Implemented as a lazy, extendable list
my $spds = grep { .&is_prime }, flat [2,3,5,7], [23,27,33,37,53,57,73,77], -> $p
  { state $o++; my $oom = 10**(1+$o); [ flat (2,3,5,7).map: -> $l { (|$p).map: $l×$oom + * } ] } … *;

say 'Smarandache prime-digitals:';
printf "%22s: %s\n", ordinal(1+$_).tclc, comma $spds[$_] for flat ^25, 99, 999, 9999, 99999;


  

You may also check:How to resolve the algorithm Flow-control structures step by step in the Perl programming language
You may also check:How to resolve the algorithm Increment a numerical string step by step in the Fōrmulæ programming language
You may also check:How to resolve the algorithm Combinations with repetitions step by step in the Crystal programming language
You may also check:How to resolve the algorithm Sorting algorithms/Bead sort step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Program name step by step in the Joy programming language