How to resolve the algorithm Smarandache prime-digital sequence step by step in the Wren programming language
Published on 12 May 2024 09:40 PM
        
        
        
        
    How to resolve the algorithm Smarandache prime-digital sequence step by step in the Wren 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 Wren programming language
Source code in the wren programming language
import "/math" for Int
var limit = 1000
var spds = List.filled(limit, 0)
spds[0] = 2
var i = 3
var count = 1
while (count < limit) {
    if (Int.isPrime(i)) {
        var digits = i.toString
        if (digits.all { |d| "2357".contains(d) }) {
            spds[count] = i
            count = count + 1
        }
    }
    i = i + 2
    if (i > 10) {
        var j = i % 10
        if (j == 1 || j == 5) {
            i = i + 2
        } else if (j == 9) {
            i = i + 4
        }
    }
}
System.print("The first 25 SPDS primes are:")
System.print(spds.take(25).toList)
System.print("\nThe 100th SPDS prime is %(spds[99])")
System.print("\nThe 1,000th SPDS prime is %(spds[999])")
  
    You may also check:How to resolve the algorithm Hello world/Text step by step in the Idris programming language
You may also check:How to resolve the algorithm Euclid-Mullin sequence step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Anagrams/Deranged anagrams step by step in the Factor programming language
You may also check:How to resolve the algorithm Intersecting number wheels step by step in the Java programming language
You may also check:How to resolve the algorithm Delete a file step by step in the Plain English programming language