Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
32
Task/Entropy/Liberty-BASIC/entropy.basic
Normal file
32
Task/Entropy/Liberty-BASIC/entropy.basic
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
dim countOfChar( 255) ' all possible one-byte ASCII chars
|
||||
|
||||
source$ ="1223334444"
|
||||
charCount =len( source$)
|
||||
usedChar$ =""
|
||||
|
||||
for i =1 to len( source$) ' count which chars are used in source
|
||||
ch$ =mid$( source$, i, 1)
|
||||
if not( instr( usedChar$, ch$)) then usedChar$ =usedChar$ +ch$
|
||||
'currentCh$ =mid$(
|
||||
j =instr( usedChar$, ch$)
|
||||
countOfChar( j) =countOfChar( j) +1
|
||||
next i
|
||||
|
||||
l =len( usedChar$)
|
||||
for i =1 to l
|
||||
probability =countOfChar( i) /charCount
|
||||
entropy =entropy -( probability *logBase( probability, 2))
|
||||
next i
|
||||
|
||||
print " Characters used and the number of occurrences of each "
|
||||
for i =1 to l
|
||||
print " '"; mid$( usedChar$, i, 1); "'", countOfChar( i)
|
||||
next i
|
||||
|
||||
print " Entropy of '"; source$; "' is "; entropy; " bits."
|
||||
print " The result should be around 1.84644 bits."
|
||||
|
||||
end
|
||||
function logBase( x, b) ' in LB log() is base 'e'.
|
||||
logBase =log( x) /log( 2)
|
||||
end function
|
||||
Loading…
Add table
Add a link
Reference in a new issue