Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Fibonacci-sequence/AutoHotkey/fibonacci-sequence-1.ahk
Normal file
18
Task/Fibonacci-sequence/AutoHotkey/fibonacci-sequence-1.ahk
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
Loop, 5
|
||||
MsgBox % fib(A_Index)
|
||||
Return
|
||||
|
||||
fib(n)
|
||||
{
|
||||
If (n < 2)
|
||||
Return n
|
||||
i := last := this := 1
|
||||
While (i <= n)
|
||||
{
|
||||
new := last + this
|
||||
last := this
|
||||
this := new
|
||||
i++
|
||||
}
|
||||
Return this
|
||||
}
|
||||
17
Task/Fibonacci-sequence/AutoHotkey/fibonacci-sequence-2.ahk
Normal file
17
Task/Fibonacci-sequence/AutoHotkey/fibonacci-sequence-2.ahk
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
Important note: the recursive version would be very slow
|
||||
without a global or static array. The iterative version
|
||||
handles also negative arguments properly.
|
||||
*/
|
||||
|
||||
FibR(n) { ; n-th Fibonacci number (n>=0, recursive with static array Fibo)
|
||||
Static
|
||||
Return n<2 ? n : Fibo%n% ? Fibo%n% : Fibo%n% := FibR(n-1)+FibR(n-2)
|
||||
}
|
||||
|
||||
Fib(n) { ; n-th Fibonacci number (n < 0 OK, iterative)
|
||||
a := 0, b := 1
|
||||
Loop % abs(n)-1
|
||||
c := b, b += a, a := c
|
||||
Return n=0 ? 0 : n>0 || n&1 ? b : -b
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue