Entropy/Narcissist: Difference between revisions

Added Wren
(Added Wren)
Line 824:
<pre>
entropy = 4.59099
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-math}}
Basically an amalgam of the code in the [[Print_itself#Wren]] and [[Entropy#Wren]] tasks.
<lang ecmascript>import "os" for Process
import "io" for File
import "/math" for Math
 
var args = Process.allArguments
var s = File.read(args[1]).trim()
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>
4.7066622885853
</pre>
 
9,485

edits