Add a bunch of new languages
This commit is contained in:
parent
1e05ecd7ee
commit
2a4d27cea0
158 changed files with 1469 additions and 0 deletions
17
Task/Entropy/Racket/entropy.rkt
Normal file
17
Task/Entropy/Racket/entropy.rkt
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#lang racket
|
||||
(require math)
|
||||
|
||||
(define (log2 x)
|
||||
(/ (log x) (log 2)))
|
||||
|
||||
(define (digits x)
|
||||
(for/list ([c (number->string x)])
|
||||
(- (char->integer c) (char->integer #\0))))
|
||||
|
||||
(define (entropy x)
|
||||
(define ds (digits x))
|
||||
(define n (length ds))
|
||||
(- (for/sum ([(d c) (in-hash (samples->hash ds))])
|
||||
(* (/ d n) (log2 (/ d n))))))
|
||||
|
||||
(entropy 1223334444)
|
||||
Loading…
Add table
Add a link
Reference in a new issue