module MoreMath::Entropy

def entropy(text)

def entropy(text)
  chars = text.chars
  size  = chars.size
  chars.each_with_object(Hash.new(0.0)) { |c, h| h[c] += 1 }.
    each_value.reduce(0.0) do |entropy, count|
      frequency = count / size
      entropy + frequency * Math.log2(frequency)
    end.abs
end