Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
32
Task/Entropy/Ring/entropy.ring
Normal file
32
Task/Entropy/Ring/entropy.ring
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
decimals(8)
|
||||
entropy = 0
|
||||
countOfChar = list(255)
|
||||
|
||||
source="1223334444"
|
||||
charCount =len( source)
|
||||
usedChar =""
|
||||
|
||||
for i =1 to len( source)
|
||||
ch =substr(source, i, 1)
|
||||
if not(substr( usedChar, ch)) usedChar =usedChar +ch ok
|
||||
j =substr( usedChar, ch)
|
||||
countOfChar[j] =countOfChar[j] +1
|
||||
next
|
||||
|
||||
l =len(usedChar)
|
||||
for i =1 to l
|
||||
probability =countOfChar[i] /charCount
|
||||
entropy =entropy - (probability *logBase(probability, 2))
|
||||
next
|
||||
|
||||
see "Characters used and the number of occurrences of each " + nl
|
||||
for i =1 to l
|
||||
see "'" + substr(usedChar, i, 1) + "' " + countOfChar[i] + nl
|
||||
next
|
||||
|
||||
see " Entropy of " + source + " is " + entropy + " bits." + nl
|
||||
see " The result should be around 1.84644 bits." + nl
|
||||
|
||||
func logBase (x, b)
|
||||
logBase =log( x) /log( 2)
|
||||
return logBase
|
||||
Loading…
Add table
Add a link
Reference in a new issue