Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View 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)
}