How to resolve the algorithm Super-Poulet numbers step by step in the Factor programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Super-Poulet numbers step by step in the Factor programming language

Table of Contents

Problem Statement

A super-Poulet number is a Poulet number (or Fermat pseudoprime to base 2) whose every divisor d evenly divides 2d − 2.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Super-Poulet numbers step by step in the Factor programming language

Source code in the factor programming language

USING: combinators.short-circuit io kernel lists lists.lazy math
math.functions math.primes math.primes.factors prettyprint
sequences ;

: super-poulet? ( n -- ? )
    {
        [ prime? not ]
        [ [ 1 - 2^ ] keep mod 1 = ]
        [ divisors [ [ 2^ 2 - ] keep divisor? ] all? ]
    } 1&& ;

: super-poulets ( -- list )
    1 lfrom [ super-poulet? ] lfilter ;

20 super-poulets ltake [ pprint bl ] leach nl


  

You may also check:How to resolve the algorithm FizzBuzz step by step in the Befunge programming language
You may also check:How to resolve the algorithm Calendar step by step in the C programming language
You may also check:How to resolve the algorithm Reduced row echelon form step by step in the Visual FoxPro programming language
You may also check:How to resolve the algorithm Department numbers step by step in the zkl programming language
You may also check:How to resolve the algorithm Jump anywhere step by step in the D programming language