Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,18 @@
(lib 'hash)
;; counter: hash-table[key]++
(define (count++ ht k )
(hash-set ht k (1+ (hash-ref! ht k 0))))
(define (hi count n )
(define pi (// count n))
(- (* pi (log2 pi))))
;; (H [string|list]) → entropy (bits)
(define (H info)
(define S (if(string? info) (string->list info) info))
(define ht (make-hash))
(define n (length S))
(for ((s S)) (count++ ht s))
(for/sum ((s (make-set S))) (hi (hash-ref ht s) n)))

View file

@ -0,0 +1,12 @@
;; by increasing entropy
(H "🔴") → 0
(H "🔵🔴") → 1
(H "1223334444") → 1.8464393446710154
(H "♖♘♗♕♔♗♘♖♙♙♙♙♙♙♙♙♙") → 2.05632607578088
(H "EchoLisp") → 3
(H "Longtemps je me suis couché de bonne heure") → 3.860828877124944
(H "azertyuiopmlkjhgfdsqwxcvbn") → 4.700439718141092
(H (for/list ((i 1000)) (random 1000))) → 9.13772704467521
(H (for/list ((i 100_000)) (random 100_000))) → 15.777516877140766
(H (for/list ((i 1000_000)) (random 1000_000))) → 19.104028424596976