How to resolve the algorithm Fibonacci n-step number sequences step by step in the Tcl programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Fibonacci n-step number sequences step by step in the Tcl programming language
Table of Contents
Problem Statement
These number series are an expansion of the ordinary Fibonacci sequence where: For small values of
n
{\displaystyle n}
, Greek numeric prefixes are sometimes used to individually name each series. Allied sequences can be generated where the initial values are changed:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Fibonacci n-step number sequences step by step in the Tcl programming language
Source code in the tcl programming language
package require Tcl 8.6
proc fibber {args} {
coroutine fib[incr ::fibs]=[join $args ","] apply {fn {
set n [info coroutine]
foreach f $fn {
if {![yield $n]} return
set n $f
}
while {[yield $n]} {
set fn [linsert [lreplace $fn 0 0] end [set n [+ {*}$fn]]]
}
} ::tcl::mathop} $args
}
proc print10 cr {
for {set i 1} {$i <= 10} {incr i} {
lappend out [$cr true]
}
puts \[[join [lappend out ...] ", "]\]
$cr false
}
puts "FIBONACCI"
print10 [fibber 1 1]
puts "TRIBONACCI"
print10 [fibber 1 1 2]
puts "TETRANACCI"
print10 [fibber 1 1 2 4]
puts "LUCAS"
print10 [fibber 2 1]
You may also check:How to resolve the algorithm Sexy primes step by step in the Quackery programming language
You may also check:How to resolve the algorithm Search a list of records step by step in the PHP programming language
You may also check:How to resolve the algorithm Long multiplication step by step in the ATS programming language
You may also check:How to resolve the algorithm Empty program step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Detect division by zero step by step in the Nim programming language