Entropy/Narcissist: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: log2 now builtin, added syntax colouring, marked p2js compatible)
Line 170: Line 170:
{{Output}}
{{Output}}
<pre>5.942956</pre>
<pre>5.942956</pre>

=={{header|AWK}}==
The record separator RS is set to end of file. So getline reads the whole file in one line.
<lang AWK>
BEGIN{FS=""
RS="\x04"#EOF
getline<"entropy.awk"
for(i=1;i<=NF;i++)H[$i]++
for(i in H)E-=(h=H[i]/NF)*log(h)
print "bytes ",NF," entropie ",E/log(2)
exit}</lang>
{{Output}}
<pre>bytes 158 entropie 5.26704</pre>


=={{header|C}}==
=={{header|C}}==