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

Published on 12 May 2024 09:40 PM

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

Source code in the basic256 programming language

arraybase 1
dim smar(100)
smar[1] = 2

cont = 1
i = 1

print 1, 2
while cont < 100
	i += 2
	if not isPrime(i) then continue while
	for j = 1 to length(string(i))
		digit = int(mid(string(i),j,1))
		if not isPrime(digit) then continue while
	next j
	cont += 1
	smar[cont] = i
	if cont = 100 or cont <= 25 then print cont, smar[cont]
end while
end

function isPrime(v)
	if v < 2 then return False
	if v mod 2 = 0 then return v = 2
	if v mod 3 = 0 then return v = 3
	d = 5
	while d * d <= v
		if v mod d = 0 then return False else d += 2
	end while
	return True
end function

  

You may also check:How to resolve the algorithm Department numbers step by step in the Prolog programming language
You may also check:How to resolve the algorithm Ordered words step by step in the Java programming language
You may also check:How to resolve the algorithm Babbage problem step by step in the PL/I programming language
You may also check:How to resolve the algorithm Fibonacci word step by step in the ooRexx programming language
You may also check:How to resolve the algorithm Base64 decode data step by step in the Jsish programming language