Fibonacci word: Difference between revisions
Content added Content deleted
Line 2,094: | Line 2,094: | ||
36 14930352 0.959418728222743 |
36 14930352 0.959418728222743 |
||
37 24157817 0.959418728222745 |
37 24157817 0.959418728222745 |
||
</pre> |
|||
=={{header|Objeck}}== |
|||
<lang objeck>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 ); |
|||
}; |
|||
} |
|||
}</lang> |
|||
Output: |
|||
<pre> |
|||
1 1 -0 |
|||
2 1 -0 |
|||
3 2 1 |
|||
4 3 0.918295834 |
|||
5 5 0.970950594 |
|||
6 8 0.954434003 |
|||
7 13 0.961236605 |
|||
8 21 0.958711883 |
|||
9 34 0.959686894 |
|||
10 55 0.959316032 |
|||
11 89 0.959457916 |
|||
12 144 0.959403754 |
|||
13 233 0.959424447 |
|||
14 377 0.959416544 |
|||
15 610 0.959419563 |
|||
16 987 0.95941841 |
|||
17 1597 0.95941885 |
|||
18 2584 0.959418682 |
|||
19 4181 0.959418746 |
|||
20 6765 0.959418721 |
|||
21 10946 0.959418731 |
|||
22 17711 0.959418727 |
|||
23 28657 0.959418729 |
|||
24 46368 0.959418728 |
|||
25 75025 0.959418728 |
|||
26 121393 0.959418728 |
|||
27 196418 0.959418728 |
|||
28 317811 0.959418728 |
|||
29 514229 0.959418728 |
|||
30 832040 0.959418728 |
|||
31 1346269 0.959418728 |
|||
32 2178309 0.959418728 |
|||
33 3524578 0.959418728 |
|||
34 5702887 0.959418728 |
|||
35 9227465 0.959418728 |
|||
36 14930352 0.959418728 |
|||
37 24157817 0.959418728 |
|||
</pre> |
</pre> |
||