How to resolve the algorithm Fibonacci word step by step in the Sidef programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Fibonacci word step by step in the Sidef 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 Sidef programming language

Source code in the sidef programming language

func entropy(s) {
    [0] + (s.chars.freq.values »/» s.len) -> reduce { |a,b|
        a - b*b.log2
    }
}

var n_max = 37
var words = ['1', '0']

{
    words.append(words[-1] + words[-2])
} * (n_max - words.len)

say ('%3s %10s %15s  %s' % ...)

for i in ^words {
    var word = words[i]
    say ('%3i %10i %15.12f  %s' % (i+1,
                                   word.len,
                                   entropy(word),
                                   word.len<30 ? word : ''))
}


  

You may also check:How to resolve the algorithm ABC problem step by step in the Ceylon programming language
You may also check:How to resolve the algorithm Additive primes step by step in the Factor programming language
You may also check:How to resolve the algorithm Count in octal step by step in the Haskell programming language
You may also check:How to resolve the algorithm 4-rings or 4-squares puzzle step by step in the PL/M programming language
You may also check:How to resolve the algorithm Multifactorial step by step in the Lua programming language