Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
21
Task/Entropy/Forth/entropy.fth
Normal file
21
Task/Entropy/Forth/entropy.fth
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
: flog2 ( f -- f ) fln 2e fln f/ ;
|
||||
|
||||
create freq 256 cells allot
|
||||
|
||||
: entropy ( str len -- f )
|
||||
freq 256 cells erase
|
||||
tuck
|
||||
bounds do
|
||||
i c@ cells freq +
|
||||
1 swap +!
|
||||
loop
|
||||
0e
|
||||
256 0 do
|
||||
i cells freq + @ ?dup if
|
||||
s>f dup s>f f/
|
||||
fdup flog2 f* f-
|
||||
then
|
||||
loop
|
||||
drop ;
|
||||
|
||||
s" 1223334444" entropy f. \ 1.84643934467102 ok
|
||||
Loading…
Add table
Add a link
Reference in a new issue