2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,9 +1,9 @@
defmodule RC do
def entropy(str) do
leng = String.length(str)
String.to_char_list(str)
|> Enum.reduce(Map.new, fn c,acc -> Dict.update(acc, c, 1, &(&1+1)) end)
|> Dict.values
String.to_charlist(str)
|> Enum.reduce(Map.new, fn c,acc -> Map.update(acc, c, 1, &(&1+1)) end)
|> Map.values
|> Enum.reduce(0, fn count, entropy ->
freq = count / leng
entropy - freq * :math.log2(freq) # log2 was added with Erlang/OTP 18