Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
21
Task/Fibonacci-sequence/PureBasic/fibonacci-sequence-3.basic
Normal file
21
Task/Fibonacci-sequence/PureBasic/fibonacci-sequence-3.basic
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
Procedure Fibonacci(n)
|
||||
Static NewMap Fib.i()
|
||||
Protected FirstRecursion
|
||||
|
||||
If MapSize(Fib())= 0 ; Init the hash table the first run
|
||||
Fib("0")=0: Fib("1")=1
|
||||
FirstRecursion = #True
|
||||
EndIf
|
||||
|
||||
If n >= 2
|
||||
Protected.s s=Str(n)
|
||||
If Not FindMapElement(Fib(),s) ; Calculate only needed parts
|
||||
Fib(s)= Fibonacci(n-1)+Fibonacci(n-2)
|
||||
EndIf
|
||||
n = Fib(s)
|
||||
EndIf
|
||||
If FirstRecursion ; Free the memory when finalizing the first call
|
||||
ClearMap(Fib())
|
||||
EndIf
|
||||
ProcedureReturn n
|
||||
EndProcedure
|
||||
Loading…
Add table
Add a link
Reference in a new issue