Jump to content

Entropy/Narcissist: Difference between revisions

Added Julia language
m (Now it works with arbitary filename)
(Added Julia language)
Line 286:
'''Example''':<lang j> load 'entropy.ijs'
4.73307</lang>
 
=={{header|Julia}}==
{{works with|Julia|0.6}}
 
<lang julia>using DataStructures
function entropy(c)
# counts elements
elements = counter(eltype(c))
for e in c push!(elements, e) end
l = length(c)
return -sum(cnt / l * log2(cnt / l) for cnt in values(elements))
end
 
println("self-entropy: ", entropy(readstring(Base.source_path())))</lang>
 
{{out}}
<pre>self-entropy: 4.632089213449782</pre>
 
=={{header|Kotlin}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.