Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
10
Task/Entropy/Common-Lisp/entropy-1.lisp
Normal file
10
Task/Entropy/Common-Lisp/entropy-1.lisp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
(defun entropy (string)
|
||||
(let ((table (make-hash-table :test 'equal))
|
||||
(entropy 0))
|
||||
(mapc (lambda (c) (setf (gethash c table) (+ (gethash c table 0) 1)))
|
||||
(coerce string 'list))
|
||||
(maphash (lambda (k v)
|
||||
(decf entropy (* (/ v (length input-string))
|
||||
(log (/ v (length input-string)) 2))))
|
||||
table)
|
||||
entropy))
|
||||
8
Task/Entropy/Common-Lisp/entropy-2.lisp
Normal file
8
Task/Entropy/Common-Lisp/entropy-2.lisp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(defun entropy (string &aux (length (length string)))
|
||||
(declare (type string string))
|
||||
(let ((table (make-hash-table)))
|
||||
(loop for char across string
|
||||
do (incf (gethash char table 0)))
|
||||
(- (loop for freq being each hash-value in table
|
||||
for freq/length = (/ freq length)
|
||||
sum (* freq/length (log freq/length 2))))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue