How to resolve the algorithm Thue-Morse step by step in the Tcl programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Thue-Morse step by step in the Tcl programming language

Table of Contents

Problem Statement

Create a Thue-Morse sequence.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Thue-Morse step by step in the Tcl programming language

Source code in the tcl programming language

proc tm_expand {s} {string map {0 01 1 10} $s}
# this could also be written as:
# interp alias {} tm_expand {} string map {0 01 1 10}

proc tm {k} {
    set s 0
    while {[incr k -1] >= 0} {
        set s [tm_expand $s]
    }
    return $s
}


for {set i 0} {$i <= 6} {incr i} {
    puts [tm $i]
}


package require sqlite3 ;# available with Tcl8.5+ core
sqlite3 db ""           ;# create in-memory database
set LIMIT 6
db eval {with recursive a(a) as (select '0' union all select replace(replace(hex(a),'30','01'),'31','10') from a) select a from a limit $LIMIT} {
    puts $a
}


  

You may also check:How to resolve the algorithm Arithmetic/Complex step by step in the Ursala programming language
You may also check:How to resolve the algorithm Dutch national flag problem step by step in the Lua programming language
You may also check:How to resolve the algorithm Deceptive numbers step by step in the Lua programming language
You may also check:How to resolve the algorithm Empty program step by step in the REBOL programming language
You may also check:How to resolve the algorithm Loops/For with a specified step step by step in the Batch File programming language