func entropy(s) { var counts = Hash.new; s.each { |c| counts{c} := 0 ++ }; var len = s.len; [0, counts.values.map {|count| var freq = count/len; freq * freq.log2 }... ]«-»; } say entropy("1223334444");
1.846439344671015493434197746305045223237
Last updated 1 year ago