The   Fibonacci Word   may be created in a manner analogous to the   Fibonacci Sequence   as described here:

    Define   F_Word1   as   1
    Define   F_Word2   as   0
    Form     F_Word3   as   F_Word2     concatenated with   F_Word1    i.e.:   01
    Form     F_Wordn   as   F_Wordn-1   concatenated with   F_wordn-2



Task

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:

   The number of characters in the word
   The word's Entropy


Related tasks
 
   Fibonacci word/fractal
   Entropy
   Entropy/Narcissist


// version 1.0.6
 
fun fibWord(n: Int): String {
    if (n < 1) throw IllegalArgumentException("Argument can't be less than 1")
    if (n == 1) return "1"
    val words = Array(n){ "" }
    words[0] = "1"
    words[1] = "0"
    for (i in 2 until n) words[i] = words[i - 1] + words[i - 2]
    return words[n - 1]
}
 
fun log2(d: Double) = Math.log(d) / Math.log(2.0)
 
fun shannon(s: String): Double {
    if (s.length <= 1) return 0.0
    val count0 = s.count { it == '0' }
    val count1 = s.length - count0
    val nn = s.length.toDouble()
    return -(count0 / nn * log2(count0 / nn) + count1 / nn * log2(count1 / nn))
}
 
fun main(args: Array<String>) {
    println("N    Length       Entropy             Word")
    println("--  --------  ------------------  ----------------------------------")
    for (i in 1..37) {
        val s = fibWord(i)
        print(String.format("%2d  %8d  %18.16f", i, s.length, shannon(s)))
        if (i < 10) println("  $s")
        else println()
    }
}