How to resolve the algorithm Ludic numbers step by step in the Factor programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Ludic numbers step by step in the Factor programming language

Table of Contents

Problem Statement

Ludic numbers   are related to prime numbers as they are generated by a sieve quite like the Sieve of Eratosthenes is used to generate prime numbers. The first ludic number is   1. To generate succeeding ludic numbers create an array of increasing integers starting from   2. (Loop)

Show all triplets of ludic numbers < 250.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Ludic numbers step by step in the Factor programming language

Source code in the factor programming language

USING: formatting fry kernel make math math.ranges namespaces
prettyprint.config sequences sequences.extras ;
IN: rosetta-code.ludic-numbers

: next-ludic ( seq -- seq' )
    dup first '[ nip _ mod zero? not ] filter-index ;

: ludics-upto-2005 ( -- a )
    22,000 2 swap [a,b] [ ! 22k suffices to produce 2005 ludics
        1 , [ building get length 2005 = ]
        [ dup first , next-ludic ] until drop
    ] { } make ;

: ludic-demo ( -- )
    100 margin set ludics-upto-2005
    [ 6 tail* ] [ [ 1000 < ] count ] [ 25 head ] tri
    "First 25 ludic numbers:\n%u\n\n"
    "Count of ludic numbers less than 1000:\n%d\n\n"
    "Ludic numbers 2000 to 2005:\n%u\n" [ printf ] tri@ ;

MAIN: ludic-demo


  

You may also check:How to resolve the algorithm Zero to the zero power step by step in the Standard ML programming language
You may also check:How to resolve the algorithm Variables step by step in the Eiffel programming language
You may also check:How to resolve the algorithm Convert seconds to compound duration step by step in the D programming language
You may also check:How to resolve the algorithm MD5 step by step in the Frink programming language
You may also check:How to resolve the algorithm Terminal control/Cursor movement step by step in the Befunge programming language