Time for an 2014 update…
This commit is contained in:
parent
372c577f83
commit
09687c4926
2520 changed files with 34227 additions and 7318 deletions
29
Task/Entropy/Seed7/entropy.seed7
Normal file
29
Task/Entropy/Seed7/entropy.seed7
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
$ include "seed7_05.s7i";
|
||||
include "float.s7i";
|
||||
include "math.s7i";
|
||||
|
||||
const func float: entropy (in string: stri) is func
|
||||
result
|
||||
var float: entropy is 0.0;
|
||||
local
|
||||
var hash [char] integer: count is (hash [char] integer).value;
|
||||
var char: ch is ' ';
|
||||
var float: p is 0.0;
|
||||
begin
|
||||
for ch range stri do
|
||||
if ch in count then
|
||||
incr(count[ch]);
|
||||
else
|
||||
count @:= [ch] 1;
|
||||
end if;
|
||||
end for;
|
||||
for key ch range count do
|
||||
p := flt(count[ch]) / flt(length(stri));
|
||||
entropy -:= p * log(p) / log(2.0);
|
||||
end for;
|
||||
end func ;
|
||||
|
||||
const proc: main is func
|
||||
begin
|
||||
writeln(entropy("1223334444") digits 5);
|
||||
end func;
|
||||
Loading…
Add table
Add a link
Reference in a new issue