Jump to content

Entropy: Difference between revisions

366 bytes added ,  4 years ago
Added Wren
(→‎Go: Map version: Corrected a variable name.)
(Added Wren)
Line 2,884:
entropy = 1.84644
entropy = 3.08496
</pre>
 
=={{header|Wren}}==
{{trans|Go}}
{{libheader|Wren-math}}
<lang ecmascript>import "/math" for Math
 
var s = "1223334444"
var m = {}
for (c in s) {
var d = m[c]
m[c] = (d) ? d + 1 : 1
}
var hm = 0
for (k in m.keys) {
var c = m[k]
hm = hm + c*Math.log2(c)
}
var l = s.count
System.print(Math.log2(l) - hm/l)</lang>
 
{{out}}
<pre>
1.846439344671
</pre>
 
9,490

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.