RosettaCodeData/Task/Entropy/Julia/entropy.julia

4 lines
175 B
Text
Raw Permalink Normal View History

2018-06-22 20:57:24 +00:00
entropy(s) = -sum(x -> x * log(2, x), count(x -> x == c, s) / length(s) for c in unique(s))
@show entropy("1223334444")
2019-09-12 10:33:56 -07:00
@show entropy([1, 2, 3, 1, 2, 1, 2, 3, 1, 2, 3, 4, 5])