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

Published on 12 May 2024 09:40 PM

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

Source code in the tcl programming language

package require Tcl 8.6

proc ludic n {
    global ludicList ludicGenerator
    for {} {[llength $ludicList] <= $n} {lappend ludicList $i} {
	set i [$ludicGenerator]
	set ludicGenerator [coroutine L_$i apply {{gen k} {
	    yield [info coroutine]
	    while true {
		set val [$gen]
		if {[incr i] == $k} {set i 0} else {yield $val}
	    }
	}} $ludicGenerator $i]
    }
    return [lindex $ludicList $n]
}
# Bootstrap the generator sequence
set ludicList [list 1]
set ludicGenerator [coroutine L_1 apply {{} {
    set n 1
    yield [info coroutine]
    while true {yield [incr n]}
}}]

# Default of 1000 is not enough
interp recursionlimit {} 5000

for {set i 0;set l {}} {$i < 25} {incr i} {lappend l [ludic $i]}
puts "first25: [join $l ,]"

for {set i 0} {[ludic $i] <= 1000} {incr i} {}
puts "below=1000: $i"

for {set i 1999;set l {}} {$i < 2005} {incr i} {lappend l [ludic $i]}
puts "2000-2005: [join $l ,]"

for {set i 0} {[ludic $i] < 256} {incr i} {set isl([ludic $i]) $i}
for {set i 1;set l {}} {$i < 250} {incr i} {
    if {[info exists isl($i)] && [info exists isl([expr {$i+2}])] && [info exists isl([expr {$i+6}])]} {
	lappend l ($i,[expr {$i+2}],[expr {$i+6}])
    }
}
puts "triplets: [join $l ,]"


  

You may also check:How to resolve the algorithm Musical scale step by step in the Java programming language
You may also check:How to resolve the algorithm Nautical bell step by step in the Seed7 programming language
You may also check:How to resolve the algorithm Abbreviations, easy step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Create an object at a given address step by step in the C programming language
You may also check:How to resolve the algorithm Tokenize a string step by step in the ACL2 programming language