Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
14
Task/Entropy/Elixir/entropy.elixir
Normal file
14
Task/Entropy/Elixir/entropy.elixir
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
defmodule RC do
|
||||
def entropy(str) do
|
||||
leng = String.length(str)
|
||||
String.split(str, "", trim: true)
|
||||
|> Enum.group_by(&(&1))
|
||||
|> Enum.map(fn{_,value} -> length(value) end)
|
||||
|> Enum.reduce(0, fn count, entropy ->
|
||||
freq = count / leng
|
||||
entropy - freq * :math.log2(freq)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
IO.inspect RC.entropy("1223334444")
|
||||
Loading…
Add table
Add a link
Reference in a new issue