Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
15
Task/Entropy/Picat/entropy.picat
Normal file
15
Task/Entropy/Picat/entropy.picat
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
go =>
|
||||
["1223334444",
|
||||
"Rosetta Code is the best site in the world!",
|
||||
"1234567890abcdefghijklmnopqrstuvwxyz",
|
||||
"Picat is fun"].map(entropy).println(),
|
||||
nl.
|
||||
|
||||
% probabilities of each element/character in L
|
||||
entropy(L) = Entropy =>
|
||||
Len = L.length,
|
||||
Occ = new_map(), % # of occurrences
|
||||
foreach(E in L)
|
||||
Occ.put(E, Occ.get(E,0) + 1)
|
||||
end,
|
||||
Entropy = -sum([P2*log2(P2) : _C=P in Occ, P2 = P/Len]).
|
||||
Loading…
Add table
Add a link
Reference in a new issue