How to resolve the algorithm Pierpont primes step by step in the Factor programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Pierpont primes step by step in the Factor programming language

Table of Contents

Problem Statement

A Pierpont prime is a prime number of the form: 2u3v + 1 for some non-negative integers u and v .

A Pierpont prime of the second kind is a prime number of the form: 2u3v - 1 for some non-negative integers u and v .

The term "Pierpont primes" is generally understood to mean the first definition, but will be called "Pierpont primes of the first kind" on this page to distinguish them.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Pierpont primes step by step in the Factor programming language

Source code in the factor programming language

USING: fry grouping io kernel locals make math math.functions
math.primes prettyprint sequences sorting ;

: pierpont ( ulim vlim quot -- seq )
    '[
        _ <iota> _ <iota> [
            [ 2 ] [ 3 ] bi* [ swap ^ ] 2bi@ * 1 @
            dup prime? [ , ] [ drop ] if
        ] cartesian-each
    ] { } make natural-sort ; inline

: .fifty ( seq -- ) 50 head 10 group simple-table. nl ;

[let
    [ + ] [ - ] [ [ 120 80 ] dip pierpont ] bi@
    :> ( first second )
    
    "First 50 Pierpont primes of the first kind:" print
    first .fifty

    "First 50 Pierpont primes of the second kind:" print
    second .fifty

    "250th Pierpont prime of the first kind: " write
    249 first nth . nl

    "250th Pierpont prime of the second kind: " write
    249 second nth .
]


  

You may also check:How to resolve the algorithm Numerical integration/Gauss-Legendre Quadrature step by step in the ATS programming language
You may also check:How to resolve the algorithm Arithmetic/Rational step by step in the Ol programming language
You may also check:How to resolve the algorithm Parameterized SQL statement step by step in the Scala programming language
You may also check:How to resolve the algorithm Emirp primes step by step in the OCaml programming language
You may also check:How to resolve the algorithm Yellowstone sequence step by step in the Rust programming language