How to resolve the algorithm Ludic numbers step by step in the Icon and Unicon programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Ludic numbers step by step in the Icon and Unicon 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 Icon and Unicon programming language
Source code in the icon programming language
global num, cascade, sieve, nfilter
procedure main(A)
lds := ludic(2005) # All we need for the four tasks.
every writes("First 25:" | (" "||!lds)\25 | "\n")
every (n := 0) +:= (!lds < 1000, 1)
write("There are ",n," Ludic numbers < 1000.")
every writes("2000th through 2005th: " | (lds[2000 to 20005]||" ") | "\n")
writes("Triplets:")
every (250 > (x := !lds)) & (250 > (x+2 = !lds)) & (250 > (x+6 = !lds)) do
writes(" [",x,",",x+2,",",x+6,"]")
write()
end
procedure ludic(limit)
candidates := create seq(2)
put(cascade := [], create {
repeat {
report(l := num, limit)
put(cascade, create (cnt:=0, repeat ((cnt+:=1)%l=0, @sieve) | @@nfilter))
cascade[-2] :=: cascade[-1] # keep this sink as the last filter
@sieve
}
})
sieve := create while num := @candidates do @@(nfilter := create !cascade)
report(1, limit)
return @sieve
end
procedure report(ludic, limit)
static count, lds
initial {count := 0; lds := []}
if (count +:= 1) > limit then lds@&main
put(lds, ludic)
end
You may also check:How to resolve the algorithm Cumulative standard deviation step by step in the Sidef programming language
You may also check:How to resolve the algorithm Inverted syntax step by step in the EchoLisp programming language
You may also check:How to resolve the algorithm Currency step by step in the C programming language
You may also check:How to resolve the algorithm Church numerals step by step in the jq programming language
You may also check:How to resolve the algorithm Literals/String step by step in the Haskell programming language