Fibonacci word: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 3,166: | Line 3,166: | ||
41 165580141 0.95941872822274421047 {the word is too wide to display, length is: 165580141} |
41 165580141 0.95941872822274421047 {the word is too wide to display, length is: 165580141} |
||
42 267914296 0.95941872822274419482 {the word is too wide to display, length is: 267914296} |
42 267914296 0.95941872822274419482 {the word is too wide to display, length is: 267914296} |
||
</pre> |
|||
=={{header|Ring}}== |
|||
<lang ring> |
|||
# Project : Fibonacci word |
|||
# Date : 2018/01/23 |
|||
# Author : Gal Zsolt [~ CalmoSoft ~] |
|||
# Email : <calmosoft@gmail.com> |
|||
fw1 = "1" |
|||
fw2 = "0" |
|||
see "N Length Entropy Word" + nl |
|||
n = 1 |
|||
see "" + n + " " + len(fw1) + " " + calcentropy(fw1,2) + " " + fw1 + nl |
|||
n = 2 |
|||
see "" + n + " " + len(fw2) + " " + calcentropy(fw2,2) + " " + fw2 + nl |
|||
for n = 1 to 55 |
|||
fw3 = fw2 + fw1 |
|||
temp = fw2 |
|||
fw2 = fw3 |
|||
fw1 = temp |
|||
if len(fw3) < 55 |
|||
see "" + (n+2) + " " + len(fw3) + " " + calcentropy(fw3,2) + " " + fw3 + nl |
|||
ok |
|||
next |
|||
func calcentropy(source,b) |
|||
decimals(11) |
|||
entropy = 0 |
|||
countOfChar = list(255) |
|||
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 |
|||
return entropy |
|||
func swap(a, b) |
|||
temp = a |
|||
a = b |
|||
b = temp |
|||
return [a, b] |
|||
func logBase (x, b) |
|||
logBase =log( x) /log( 2) |
|||
return logBase |
|||
</lang> |
|||
Output: |
|||
<pre> |
|||
N ength Entropy Word |
|||
1 1 0.000000000000000 1 |
|||
2 1 0.000000000000000 0 |
|||
3 2 1.000000000000000 01 |
|||
4 3 0.918295834054490 010 |
|||
5 5 0.970950594454669 01001 |
|||
6 8 0.954434002924965 01001010 |
|||
7 13 0.961236604722876 0100101001001 |
|||
8 21 0.958711882977132 010010100100101001010 |
|||
9 34 0.959686893774217 0100101001001010010100100101001001 |
|||
10 55 0.959316032054378 |
|||
11 89 0.959457915838670 |
|||
12 144 0.959403754221023 |
|||
13 233 0.959424446955987 |
|||
14 377 0.959416543740441 |
|||
15 610 0.959419562603144 |
|||
16 987 0.959418409515224 |
|||
17 1597 0.959418849957810 |
|||
18 2584 0.959418681724032 |
|||
19 4181 0.959418745983664 |
|||
20 6765 0.959418721438676 |
|||
21 10946 0.959418730814028 |
|||
22 17711 0.959418727232962 |
|||
23 28657 0.959418728600807 |
|||
24 46368 0.959418728078337 |
|||
25 75025 0.959418728277903 |
|||
26 121393 0.959418728201675 |
|||
27 196418 0.959418728230792 |
|||
28 317811 0.959418728219670 |
|||
29 514229 0.959418728223918 |
|||
30 832040 0.959418728222296 |
|||
31 1346269 0.959418728222916 |
|||
32 2178309 0.959418728222679 |
|||
33 3524578 0.959418728222769 |
|||
34 5702887 0.959418728222735 |
|||
35 9227465 0.959418728222748 |
|||
36 14930352 0.959418728222743 |
|||
37 24157817 0.959418728222745 |
|||
</pre> |
</pre> |
||