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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Emirp primes step by step in the FutureBasic 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 FutureBasic programming language

Source code in the futurebasic programming language

local fn IsPrime( n as NSUInteger ) as BOOL
  BOOL       isPrime = YES
  NSUInteger i
  
  if n < 2        then exit fn = NO
  if n = 2        then exit fn = YES
  if n mod 2 == 0 then exit fn = NO
  for i = 3 to int(n^.5) step 2
    if n mod i == 0 then exit fn = NO
  next
end fn = isPrime


local fn ReverseNumber( n as NSUInteger ) as NSUInteger
  NSInteger sum = 0
  
  if n < 10 then exit fn = n
  while ( n > 0 )
    sum = 10 * sum  + ( n mod 10 )
    n /= 10
  wend
end fn = sum


local fn IsEmirp( n as NSUInteger ) as BOOL
  BOOL result = NO
  NSUInteger r = fn ReverseNumber(n)
  if r != n and fn IsPrime(n) and fn IsPrime(r) then result = YES
end fn = result


local fn GetEmirpPrimes
  NSUInteger count = 0, i = 13
  
  printf @"\nThe first 20 Emirp primes are:"
  do
    if fn IsEmirp(i) then printf @"%4lu\b", i : count++
    i += 2
  until ( count == 20 )
  
  printf @"\n\nThe Emirp primes between 7700 and 8000 are:"
  i = 7701
  while ( i < 8000 )
    if fn IsEmirp(i) then printf @"%5lu\b", i
    i += 2
  wend
    
  i = 13 : count = 0
  while (1)
    if fn IsEmirp(i) then count++
    if count = 10000 then exit while
    i += 2
  wend
  printf @"\n\nThe 10,000th Emirp prime is: %lu", i
  
end fn

fn GetEmirpPrimes

HandleEvents

  

You may also check:How to resolve the algorithm Least common multiple step by step in the Bracmat programming language
You may also check:How to resolve the algorithm Dynamic variable names step by step in the Perl programming language
You may also check:How to resolve the algorithm User input/Graphical step by step in the Scratch programming language
You may also check:How to resolve the algorithm Sudan function step by step in the Factor programming language
You may also check:How to resolve the algorithm Roots of a function step by step in the Lambdatalk programming language