How to resolve the algorithm Thue-Morse step by step in the XLISP programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Thue-Morse step by step in the XLISP 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 XLISP programming language
Source code in the xlisp programming language
(defun thue-morse (n)
(defun flip-bits (s)
(defun flip (l)
(if (not (null l))
(cons
(if (equal (car l) #\1)
#\0
#\1)
(flip (cdr l)))))
(list->string (flip (string->list s))))
(if (= n 0)
"0"
(string-append (thue-morse (- n 1)) (flip-bits (thue-morse (- n 1))))))
; define RANGE, for testing purposes
(defun range (x y)
(if (< x y)
(cons x (range (+ x 1) y))))
; test THUE-MORSE by printing the strings it returns for n = 0 to n = 6
(mapcar (lambda (n) (print (thue-morse n))) (range 0 7))
You may also check:How to resolve the algorithm Stern-Brocot sequence step by step in the Amazing Hopper programming language
You may also check:How to resolve the algorithm Determine if a string is collapsible step by step in the REXX programming language
You may also check:How to resolve the algorithm Runtime evaluation step by step in the MATLAB programming language
You may also check:How to resolve the algorithm Associative array/Iteration step by step in the Jq programming language
You may also check:How to resolve the algorithm Sudan function step by step in the J programming language