How to resolve the algorithm Fibonacci word step by step in the Common Lisp programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Fibonacci word step by step in the Common Lisp programming language
Table of Contents
Problem Statement
The Fibonacci Word may be created in a manner analogous to the Fibonacci Sequence as described here:
Perform the above steps for n = 37. You may display the first few but not the larger values of n. {Doing so will get the task's author into trouble with them what be (again!).} Instead, create a table for F_Words 1 to 37 which shows:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Fibonacci word step by step in the Common Lisp programming language
Source code in the common programming language
(defun make-fibwords (array)
(loop for i from 0 below 37
for j = "0" then (concatenate 'string j k)
and k = "1" then j
do (setf (aref array i) k))
array)
(defvar *fib* (make-fibwords (make-array 37)))
(defun entropy (string)
(let ((table (make-hash-table :test 'eql))
(entropy 0d0)
(n (length string)))
(mapc (lambda (c)
(setf (gethash c table) (+ (gethash c table 0) 1)))
(coerce string 'list))
(maphash (lambda (k v)
(declare (ignore k))
(decf entropy (* (/ v n) (log (/ v n) 2))))
table)
entropy))
(defun string-or-dots (string)
(if (> (length string) 40)
"..."
string))
(format t "~2A ~10A ~17A ~A~%" "N" "Length" "Entropy" "Fibword")
(loop for i below 37
for n = (aref *fib* i) do
(format t "~2D ~10D ~17,15F ~A~%"
(1+ i) (length n) (entropy n) (string-or-dots n)))
You may also check:How to resolve the algorithm Balanced brackets step by step in the Quackery programming language
You may also check:How to resolve the algorithm Population count step by step in the Ol programming language
You may also check:How to resolve the algorithm N'th step by step in the Raku programming language
You may also check:How to resolve the algorithm Longest common substring step by step in the Elixir programming language
You may also check:How to resolve the algorithm Bitmap step by step in the Haskell programming language