#!/usr/bin/ruby

#
## http://rosettacode.org/wiki/Entropy/Narcissist
#

func entropy(s) {
    [0,
        s.chars.freq.values.map {|c|
            var f = c/s.len
            f * f.log2
        }...
    ]«-»
}

say entropy(File(__FILE__).open_r.slurp)
