How to resolve the algorithm Ludic numbers step by step in the Action! programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Ludic numbers step by step in the Action! 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 Action! programming language
Source code in the action! programming language
DEFINE NOTLUDIC="0"
DEFINE LUDIC="1"
DEFINE UNKNOWN="2"
PROC LudicSieve(BYTE ARRAY a INT count)
INT i,j,k
SetBlock(a,count,UNKNOWN)
a(0)=NOTLUDIC
a(1)=LUDIC
i=2
WHILE i
DO
IF a(i)=UNKNOWN THEN
a(i)=LUDIC
j=i k=0
WHILE j
DO
IF a(j)=UNKNOWN THEN
k==+1
IF k=i THEN
a(j)=NOTLUDIC
k=0
FI
FI
j==+1
OD
FI
i==+1
Poke(77,0) ;turn off the attract mode
OD
RETURN
PROC PrintLudicNumbers(BYTE ARRAY a INT count,first,last)
INT i,j
i=1 j=0
WHILE i
DO
IF a(i)=LUDIC THEN
IF j>=first THEN
PrintI(i) Put(32)
FI
j==+1
FI
i==+1
OD
PutE() PutE()
RETURN
INT FUNC CountLudicNumbers(BYTE ARRAY a INT max)
INT i,res
res=0
FOR i=1 TO max
DO
IF a(i)=LUDIC THEN
res==+1
FI
OD
RETURN (res)
PROC PrintLudicTriplets(BYTE ARRAY a INT max)
INT i,j
j=0
FOR i=0 TO max-6
DO
IF a(i)=LUDIC AND a(i+2)=LUDIC AND a(i+6)=LUDIC THEN
j==+1
PrintF("%I. %I-%I-%I%E",j,i,i+2,i+6)
FI
OD
RETURN
PROC Main()
DEFINE COUNT="22000"
BYTE ARRAY lud(COUNT+1)
INT i,n
PrintE("Please wait...")
LudicSieve(lud,COUNT+1)
Put(125) PutE() ;clear the screen
PrintE("First 25 ludic numbers:")
PrintLudicNumbers(lud,COUNT+1,0,24)
n=CountLudicNumbers(lud,1000)
PrintF("There are %I ludic numbers <= 1000%E%E",n)
PrintE("2000'th..2005'th ludic numbers:")
PrintLudicNumbers(lud,COUNT+1,1999,2004)
PrintE("Ludic triplets below 250")
PrintLudicTriplets(lud,249)
RETURN
You may also check:How to resolve the algorithm Infinity step by step in the Eiffel programming language
You may also check:How to resolve the algorithm Continued fraction step by step in the Ruby programming language
You may also check:How to resolve the algorithm Shell one-liner step by step in the Wart programming language
You may also check:How to resolve the algorithm Sorting algorithms/Gnome sort step by step in the jq programming language
You may also check:How to resolve the algorithm Bitmap/Bézier curves/Quadratic step by step in the FutureBasic programming language