How to resolve the algorithm Emirp primes step by step in the Oforth programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Emirp primes step by step in the Oforth programming language

Table of Contents

Problem Statement

An   emirp   (prime spelled backwards)   are primes that when reversed   (in their decimal representation)   are a different prime. (This rules out palindromic primes.)

In each list, the numbers should be in order. Invoke the (same) program once per task requirement, this will show what limit is used as the upper bound for calculating surplus (regular) primes. The specific method of how to determine if a range or if specific values are to be shown will be left to the programmer.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Emirp primes step by step in the Oforth programming language

Source code in the oforth programming language

: isEmirp(n)
   n isPrime ifFalse: [ false return ]
   n asString reverse asInteger dup n == ifTrue: [ drop false ] else: [ isPrime ] ;

: main(min, max, length)
| l |
   ListBuffer new ->l
   min while(l size length < ) [
      dup max > ifTrue: [ break ] 
      dup isEmirp ifTrue: [ dup l add ] 1 + 
      ] 
   drop l ;

  

You may also check:How to resolve the algorithm Sorting algorithms/Shell sort step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Compiler/code generator step by step in the Nim programming language
You may also check:How to resolve the algorithm Nested function step by step in the 11l programming language
You may also check:How to resolve the algorithm Averages/Mode step by step in the Jakt programming language
You may also check:How to resolve the algorithm Factors of an integer step by step in the Ring programming language