Entropy: Difference between revisions
→{{header|Ruby}}: Use tally method
Cyril Nocton (talk | contribs) |
(→{{header|Ruby}}: Use tally method) |
||
Line 2,914:
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">def entropy(s)
counts =
leng = s.length.to_f▼
▲ leng = s.length
counts.values.reduce(0) do |entropy, count|
freq = count / leng
Line 2,931 ⟶ 2,930:
1.8464393446710154
</pre>
=={{header|Run BASIC}}==
|