June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
58
Task/Fibonacci-word/Objeck/fibonacci-word.objeck
Normal file
58
Task/Fibonacci-word/Objeck/fibonacci-word.objeck
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
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 );
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue