RosettaCodeData/Task/Entropy/EasyLang/entropy.easy

13 lines
226 B
Text
Raw Permalink Normal View History

2023-10-02 18:11:16 -07:00
func entropy s$ .
len d[] 255
for c$ in strchars s$
d[strcode c$] += 1
.
2026-02-01 16:33:20 -08:00
for cnt in d[] : if cnt > 0
prop = cnt / len s$
entr -= prop * log prop 2
2023-10-02 18:11:16 -07:00
.
return entr
.
print entropy "1223334444"