How to resolve the algorithm Extensible prime generator step by step in the FutureBasic programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Extensible prime generator step by step in the FutureBasic programming language

Table of Contents

Problem Statement

Write a generator of prime numbers, in order, that will automatically adjust to accommodate the generation of any reasonably high prime. The routine should demonstrably rely on either:

The routine should be used to:

Show output on this page. Note: You may reference code already on this site if it is written to be imported/included, then only the code necessary for import and the performance of this task need be shown. (It is also important to leave a forward link on the referenced tasks entry so that later editors know that the code is used for multiple tasks). Note 2: If a languages in-built prime generator is extensible or is guaranteed to generate primes up to a system limit, (231 or memory overflow for example), then this may be used as long as an explanation of the limits of the prime generator is also given. (Which may include a link to/excerpt from, language documentation). Note 3:The task is written so it may be useful in solving the task   Emirp primes   as well as others (depending on its efficiency).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Extensible prime generator 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 ExtensiblePrimes
  long c = 0, n = 2, count = 0, track = 0
  
  printf @"The first 20 prime numbers are: "
  while ( c < 20 )
    if ( fn IsPrime(n) )
      printf @"%ld \b", n
      c++
    end if
    n++
  wend
  
  printf @"\n\nPrimes between 100 and 150 include: "
  for n = 100 to 150
    if ( fn IsPrime(n) ) then printf @"%ld \b", n
  next
  
  printf @"\n\nPrimes beween 7,700 and 8,000 include: "
  c = 0
  for n = 7700 to 8000
    if ( fn IsPrime(n) ) then c += fn IsPrime(n) : printf @"%ld \b", n : count++ : track++
    if count = 10 then print : count = 0
  next
  printf @"There are %ld primes beween 7,700 and 8,000.", track
  
  printf @"\nThe 10,000th prime is: "
  c = 0 : n = 1
  while ( c < 10000 )
    n++
    c += fn IsPrime(n)
  wend
  printf @"%ld", n
end fn

CFTimeInterval t

t = fn CACurrentMediaTime
fn ExtensiblePrimes
printf @"\nCompute time: %.3f ms",(fn CACurrentMediaTime-t)*100
HandleEvents

  

You may also check:How to resolve the algorithm Variable size/Get step by step in the Ol programming language
You may also check:How to resolve the algorithm Text processing/Max licenses in use step by step in the Clojure programming language
You may also check:How to resolve the algorithm Optional parameters step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Self-describing numbers step by step in the Delphi programming language
You may also check:How to resolve the algorithm Create a file step by step in the J programming language