Entropy: Difference between revisions
Content added Content deleted
(add Crystal example; translated from Python) |
|||
Line 687: | Line 687: | ||
hist = {} of Char => Int32 |
hist = {} of Char => Int32 |
||
l = 0 |
l = 0 |
||
source.each_char do |e| |
|||
n = 0 |
|||
loop do |
|||
e = source[n] |
|||
if !hist.has_key? e |
if !hist.has_key? e |
||
hist[e] = 0 |
hist[e] = 0 |
||
end |
end |
||
hist[e] += 1 |
hist[e] += 1 |
||
n += 1 |
|||
break if n == source.size |
|||
end |
end |
||
return Tuple.new(source.size, hist) |
return Tuple.new(source.size, hist) |