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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Smarandache prime-digital sequence step by step in the XPL0 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 XPL0 programming language

Source code in the xpl0 programming language

func IsPrime(N);        \Return 'true' if N is prime
int  N, I;
[if N <= 2 then return N = 2;
if (N&1) = 0 then \even >2\ return false;
for I:= 3 to sqrt(N) do
    [if rem(N/I) = 0 then return false;
    I:= I+1;
    ];
return true;
];

func PrimeDigits(N);    \Return 'true' if all digits are prime
int  N;
[repeat N:= N/10;
        case rem(0) of
          0, 1, 4, 6, 8, 9: return false
        other [];
until   N = 0;
return true;
];

int C, N;
[C:= 0;  N:= 2;
loop    [if IsPrime(N) then
            if PrimeDigits(N) then
                [C:= C+1;
                if C <= 25 then
                    [IntOut(0, N);  ChOut(0, ^ )];
                if C = 100 then
                    [Text(0, "^m^j100th: ");  IntOut(0, N)];
                if C = 1000 then quit;
                ];
        N:= N+1;
        ];
Text(0, "^m^j1000th: ");  IntOut(0, N);  CrLf(0);
]

  

You may also check:How to resolve the algorithm Weird numbers step by step in the AppleScript programming language
You may also check:How to resolve the algorithm QR decomposition step by step in the Julia programming language
You may also check:How to resolve the algorithm Fractal tree step by step in the Rust programming language
You may also check:How to resolve the algorithm Stirling numbers of the first kind step by step in the REXX programming language
You may also check:How to resolve the algorithm Enumerations step by step in the Ring programming language