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


use Collection;
 
class FibonacciWord {
  function : native : GetEntropy(result : String) ~ Float {
    frequencies := IntMap->New();
 
    each(i : result) {
      c := result->Get(i);
 
      if(frequencies->Has(c)) {
        count := frequencies->Find(c)->As(IntHolder);
        count->Set(count->Get() + 1);
      }
      else {
        frequencies->Insert(c, IntHolder->New(1));
      };
    };
 
    length := result->Size();
    entropy := 0.0;
 
    counts := frequencies->GetValues(); 
    each(i : counts) {
      count := counts->Get(i)->As(IntHolder)->Get();
      freq := count->As(Float) / length;
      entropy += freq * (freq->Log() / 2.0->Log());
    };
 
    return -1 * entropy;
  }
 
  function : native : PrintLine(n : Int, result : String) ~ Nil {
    n->Print();
    '\t'->Print();
 
    result->Size()->Print();
    "\t\t"->Print();
 
    GetEntropy(result)->PrintLine();
    }
 
  function : Main(args : String[]) ~ Nil {
    firstString := "1";
    n := 1;
    PrintLine( n, firstString );
    secondString := "0";
    n += 1;
    PrintLine( n, secondString );
 
    while(n < 37) {
      resultString := "{$secondString}{$firstString}";
      firstString := secondString;
      secondString := resultString;
      n  += 1;
      PrintLine( n, resultString );
    };
  }  
}