Entropy: Difference between revisions

492 bytes added ,  11 years ago
no edit summary
(Added C)
No edit summary
Line 98:
Rosetta Code is the best site in the world!
3.646513</lang>
 
=={{header|Common Lisp}}==
<lang lisp>(defun entropy(input-string)
(let ((frequency-table (make-hash-table :test 'equal))
(entropy 0))
(map 'nil #'(lambda(c) (setf (gethash c frequency-table) (if (gethash c frequency-table) (+ (gethash c frequency-table) 1) 1))) (coerce input-string 'list))
(maphash #'(lambda(k v) (setf entropy (+ entropy (* -1 (/ v (length input-string)) (log (/ v (length input-string)) 2))))) frequency-table)
entropy))
</lang>
 
=={{header|D}}==
Anonymous user