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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Ludic numbers step by step in the Oforth 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 Oforth programming language

Source code in the oforth programming language

: ludic(n)
| ludics l p |
   ListBuffer newSize(n) seqFrom(2, n) over addAll ->l
   ListBuffer newSize(n) dup add(1) dup ->ludics

   while(l notEmpty) [
      l removeFirst dup ludics add ->p  
      l size p / p * while(dup 1 > ) [ dup l removeAt drop p - ] drop
      ] ;

: ludics
| l i |
   ludic(22000) ->l
   "First 25     : " print l left(25) println
   "Below 1000   : " print l filter(#[ 1000 < ]) size println
   "2000 to 2005 : " print l extract(2000, 2005) println

   250 loop: i [
      l include(i) ifFalse: [ continue ]
      l include(i 2 +) ifFalse: [ continue ]
      l include(i 6 +) ifFalse: [ continue ]
      i print ", " print i 2 + print ", " print i 6 + println
      ] ;

  

You may also check:How to resolve the algorithm Odd word problem step by step in the C programming language
You may also check:How to resolve the algorithm Read a file line by line step by step in the Wren programming language
You may also check:How to resolve the algorithm Gaussian elimination step by step in the jq programming language
You may also check:How to resolve the algorithm The Twelve Days of Christmas step by step in the Python programming language
You may also check:How to resolve the algorithm Synchronous concurrency step by step in the C# programming language