How to resolve the algorithm Fibonacci word step by step in the PureBasic programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Fibonacci word step by step in the PureBasic programming language
Table of Contents
Problem Statement
The Fibonacci Word may be created in a manner analogous to the Fibonacci Sequence as described here:
Perform the above steps for n = 37. You may display the first few but not the larger values of n. {Doing so will get the task's author into trouble with them what be (again!).} Instead, create a table for F_Words 1 to 37 which shows:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Fibonacci word step by step in the PureBasic programming language
Source code in the purebasic programming language
EnableExplicit
Define fwx$, n.i
NewMap uchar.i()
Macro RowPrint(ns,ls,es,ws)
Print(RSet(ns,4," ")+RSet(ls,12," ")+" "+es+" ") : If Len(ws)<55 : PrintN(ws) : Else : PrintN("...") : EndIf
EndMacro
Procedure.d nlog2(x.d) : ProcedureReturn Log(x)/Log(2) : EndProcedure
Procedure countchar(s$, Map uchar())
If Len(s$)
uchar(Left(s$,1))=CountString(s$,Left(s$,1)) : s$=RemoveString(s$,Left(s$,1))
ProcedureReturn countchar(s$, uchar())
EndIf
EndProcedure
Procedure.d ce(fw$)
Define e.d
Shared uchar()
countchar(fw$,uchar())
ForEach uchar() : e-uchar()/Len(fw$)*nlog2(uchar()/Len(fw$)) : Next
ProcedureReturn e
EndProcedure
Procedure.s fw(n.i,a$="0",b$="1",m.i=2)
Select n : Case 1 : ProcedureReturn a$ : Case 2 : ProcedureReturn b$ : EndSelect
If m<n : ProcedureReturn fw(n,b$+a$,a$,m+1) : EndIf
ProcedureReturn Mid(a$,3)+ReverseString(Left(a$,2))
EndProcedure
OpenConsole()
PrintN(" N Length Entropy Word")
For n=1 To 37 : fwx$=fw(n) : RowPrint(Str(n),Str(Len(fwx$)),StrD(ce(fwx$),15),fwx$) : Next
Input()
You may also check:How to resolve the algorithm Knapsack problem/Continuous step by step in the zkl programming language
You may also check:How to resolve the algorithm Draw a sphere step by step in the Yabasic programming language
You may also check:How to resolve the algorithm Arithmetic numbers step by step in the Draco programming language
You may also check:How to resolve the algorithm Benford's law step by step in the GW-BASIC programming language
You may also check:How to resolve the algorithm Runtime evaluation step by step in the ALGOL 68 programming language