Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
42
Task/Entropy/Elena/entropy.elena
Normal file
42
Task/Entropy/Elena/entropy.elena
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import system'math;
|
||||
import system'collections;
|
||||
import system'routines;
|
||||
import extensions;
|
||||
|
||||
extension op
|
||||
{
|
||||
logTwo()
|
||||
= self.ln() / 2.ln();
|
||||
}
|
||||
|
||||
public program()
|
||||
{
|
||||
var input := console.readLine();
|
||||
var infoC := 0.0r;
|
||||
var table := Dictionary.new();
|
||||
|
||||
input.forEach:(ch)
|
||||
{
|
||||
var n := table[ch];
|
||||
if (nil == n)
|
||||
{
|
||||
table[ch] := 1
|
||||
}
|
||||
else
|
||||
{
|
||||
table[ch] := n + 1
|
||||
}
|
||||
};
|
||||
|
||||
var freq := 0;
|
||||
table.forEach:(letter)
|
||||
{
|
||||
freq := letter.toInt().realDiv(input.Length);
|
||||
|
||||
infoC += (freq * freq.logTwo())
|
||||
};
|
||||
|
||||
infoC *= -1;
|
||||
|
||||
console.printLine("The Entropy of ", input, " is ", infoC)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue