RosettaCodeData/Task/Entropy/Sidef/entropy.sidef

11 lines
221 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
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");