Entropy: Difference between revisions

Content deleted Content added
Querfeld (talk | contribs)
→‎Python: More succinct version: move constant operations out of the sum
Querfeld (talk | contribs)
→‎AWK: simplify
Line 286:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">#!/usr/bin/awk -f
{
N = length
for (i = 1; i <= length($0)N; i++i) {
++H[substr($0, i, 1)]++;
N++;
}
}
 
END {
for (i in H) {
p S += H[i]/N; * log(H[i])
E print (log(N) -= S p/ N) */ log(p2);
}
print E/log(2);
}</syntaxhighlight>
{{out|Usage}}
<syntaxhighlight lang="bashsh"> echo 1223334444 |./entropy.awk
1.84644 </syntaxhighlight>
 
=={{header|BASIC}}==