How to resolve the algorithm Van Eck sequence step by step in the Tcl programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Van Eck sequence step by step in the Tcl programming language
Table of Contents
Problem Statement
The sequence is generated by following this pseudo-code:
Using A: Using B: Using C: Using B: Using C: (zero last occurred two steps back - before the one) Using B: Using C: (two last occurred two steps back - before the zero) Using C: (two last occurred one step back) Using C: (one last appeared six steps back) ...
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Van Eck sequence step by step in the Tcl programming language
Source code in the tcl programming language
## Mathematically, the first term has index "0", not "1". We do that, also.
set ::vE 0
proc vanEck {n} {
global vE vEocc
while {$n >= [set k [expr {[llength $vE] - 1}]]} {
set kv [lindex $vE $k]
## value $kv @ $k is not yet stuffed into vEocc()
lappend vE [expr {[info exists vEocc($kv)] ? $k - $vEocc($kv) : 0}]
set vEocc($kv) $k
}
return [lindex $vE $n]
}
proc show {func from to} {
for {set n $from} {$n <= $to} {incr n} {
append r " " [$func $n]
}
puts "${func}($from..$to) =$r"
}
show vanEck 0 9
show vanEck 990 999
You may also check:How to resolve the algorithm Feigenbaum constant calculation step by step in the Java programming language
You may also check:How to resolve the algorithm Median filter step by step in the Wren programming language
You may also check:How to resolve the algorithm Abundant, deficient and perfect number classifications step by step in the Jsish programming language
You may also check:How to resolve the algorithm Textonyms step by step in the Delphi programming language
You may also check:How to resolve the algorithm Idiomatically determine all the characters that can be used for symbols step by step in the XPL0 programming language