How to resolve the algorithm Primorial numbers step by step in the jq programming language

Published on 12 May 2024 09:40 PM
#Jq

How to resolve the algorithm Primorial numbers step by step in the jq programming language

Table of Contents

Problem Statement

Primorial numbers are those formed by multiplying successive prime numbers.

The primorial number series is: To express this mathematically,   primorialn   is   the product of the first   n   (successive) primes:

In some sense, generating primorial numbers is similar to factorials. As with factorials, primorial numbers get large quickly.

By   length   (above), it is meant the number of decimal digits in the numbers.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Primorial numbers step by step in the jq programming language

Source code in the jq programming language

def primes:
  2, range(3; infinite; 2) | select(is_prime);
    
# generate an infinite stream of primorials beginning with primorial(0)
def primorials:
  0, foreach primes as $p (1; .*$p; .);

"The first ten primorial numbers are:",
limit(10; primorials),

"\nThe primorials with the given index have the lengths shown:",
([10, 100, 1000, 10000, 100000] as $sample
| limit($sample|length;
    foreach primes as $p ([0,1];   # [index, primorial]
      .[0]+=1 | .[1] *= $p;
      select(.[0]|IN($sample[])) | [.[0], (.[1]|tostring|length)] ) ))

  

You may also check:How to resolve the algorithm Egyptian division step by step in the Tailspin programming language
You may also check:How to resolve the algorithm Move-to-front algorithm step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Empty string step by step in the Slope programming language
You may also check:How to resolve the algorithm Pick random element step by step in the Powershell programming language
You may also check:How to resolve the algorithm Faulhaber's formula step by step in the Haskell programming language