Entropy: Difference between revisions

548 bytes added ,  2 years ago
Line 2,184:
Rosetta Code : 3.084963
1234567890abcdefghijklmnopqrstuvwxyz : 5.169925</pre>
 
=={{header|Picat}}==
<lang Picat>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]).</lang>
 
Output:
<pre>[1.846439344671016,3.646513010214172,5.169925001442309,3.251629167387823]</pre>
 
 
=={{header|PicoLisp}}==
495

edits