2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
35
Task/Fibonacci-word/ZX-Spectrum-Basic/fibonacci-word.zx
Normal file
35
Task/Fibonacci-word/ZX-Spectrum-Basic/fibonacci-word.zx
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
10 LET x$="1": LET y$="0": LET z$=""
|
||||
20 PRINT "N, Length, Entropy, Word"
|
||||
30 LET n=1
|
||||
40 PRINT n;" ";LEN x$;" ";
|
||||
50 LET s$=x$: LET base=2: GO SUB 1000
|
||||
60 PRINT entropy
|
||||
70 PRINT x$
|
||||
80 LET n=2
|
||||
90 PRINT n;" ";LEN y$;" ";
|
||||
100 LET s$=y$: GO SUB 1000
|
||||
110 PRINT entropy
|
||||
120 PRINT y$
|
||||
130 FOR n=1 TO 18
|
||||
140 LET x$="1": LET y$="0"
|
||||
150 FOR i=1 TO n
|
||||
160 LET z$=y$+x$
|
||||
170 LET p$=x$: LET x$=y$: LET y$=p$
|
||||
180 LET p$=y$: LET y$=z$: LET z$=p$
|
||||
190 NEXT i
|
||||
200 LET x$="": LET z$=""
|
||||
210 LET s$=y$: GO SUB 1000
|
||||
220 PRINT n+2;" ";LEN y$;" ";entropy
|
||||
230 PRINT y$ AND (LEN y$<32)
|
||||
240 NEXT n
|
||||
250 STOP
|
||||
1000 REM Calculate entropy
|
||||
1010 LET sourcelen=LEN s$: LET entropy=0
|
||||
1020 DIM t(255)
|
||||
1030 FOR j=1 TO sourcelen
|
||||
1040 LET digit=VAL s$(j)+1: LET t(digit)=t(digit)+1
|
||||
1050 NEXT j
|
||||
1060 FOR j=1 TO 255
|
||||
1070 IF t(j)>0 THEN LET prop=t(j)/sourcelen: LET entropy=entropy-(prop*LN (prop)/LN (base))
|
||||
1080 NEXT j
|
||||
1090 RETURN
|
||||
Loading…
Add table
Add a link
Reference in a new issue