Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 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.graphemes(str)
|
||||
|> 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