1234567891011121314151617 |
- #!/usr/bin/ruby
- #
- ## https://rosettacode.org/wiki/Entropy
- #
- 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");
|