Entropy: Difference between revisions
→Common Lisp
(→{{header|Vlang}}: Rename "Vlang" in "V (Vlang)") |
Cyril Nocton (talk | contribs) |
||
Line 693:
for freq/length = (/ freq length)
sum (* freq/length (log freq/length 2))))))</syntaxhighlight>
====Alternative version====
'' DRAFT''
1. Program
<syntaxhighlight lang="lisp">;; 22.10.28
(defun H2 (X)
(let* ((s (remove-duplicates X)) (m (length X)) (n (length s)) c)
(loop for i from 0 below n summing
(progn
(setf c (count (char s i) X))
(- (* (/ c m) (log (/ c m) 2)))))))</syntaxhighlight>
2. Execution
<pre>(print (H2 "1223334444"))</pre>
{{out}}
<pre>1.8464394</pre>
That's all Folks !
''cyril nocton (cyril.nocton@gmail.com) w/ google translate''
=={{header|Crystal}}==
|