RosettaCodeData/Task/Entropy/Julia/entropy.julia

4 lines
175 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
entropy(s) = -sum(x -> x * log(2, x), count(x -> x == c, s) / length(s) for c in unique(s))
@show entropy("1223334444")
@show entropy([1, 2, 3, 1, 2, 1, 2, 3, 1, 2, 3, 4, 5])