Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
12
Task/Entropy/ZX-Spectrum-Basic/entropy.basic
Normal file
12
Task/Entropy/ZX-Spectrum-Basic/entropy.basic
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
10 LET s$="1223334444": LET base=2: LET entropy=0
|
||||
20 LET sourcelen=LEN s$
|
||||
30 DIM t(255)
|
||||
40 FOR i=1 TO sourcelen
|
||||
50 LET number= CODE s$(i)
|
||||
60 LET t(number)=t(number)+1
|
||||
70 NEXT i
|
||||
80 PRINT "Char";TAB (6);"Count"
|
||||
90 FOR i=1 TO 255
|
||||
100 IF t(i)<>0 THEN PRINT CHR$ i;TAB (6);t(i): LET prop=t(i)/sourcelen: LET entropy=entropy-(prop*(LN prop)/(LN base))
|
||||
110 NEXT i
|
||||
120 PRINT '"The Entropy of """;s$;""" is ";entropy
|
||||
Loading…
Add table
Add a link
Reference in a new issue