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


import math, strformat, strutils
 
 
func entropy(str: string): float =
  ## return the entropy of a fibword string.
  if str.len <= 1: return 0.0
  let strlen = str.len.toFloat
  let count0 = str.count('0').toFloat
  let count1 = strlen - count0
  result = -(count0 / strlen * log2(count0 / strlen) + count1 / strlen * log2(count1 / strlen))
 
 
iterator fibword(): string =
  ## Yield the successive fibwords.
  var a = "1"
  var b = "0"
  yield a
  yield b
  while true:
    a = b & a
    swap a, b
    yield b
 
 
when isMainModule:
  echo " n    length       entropy"
  echo "————————————————————————————————"
  var n = 0
  for str in fibword():
    inc n
    echo fmt"{n:2}  {str.len:8}  {entropy(str):.16f}"
    if n == 37: break