June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,64 @@
# Project : Fibonacci n-step number sequences
# Date : 2017/10/07
# Author : Gal Zsolt (~ CalmoSoft ~)
# Email : <calmosoft@gmail.com>
f = list(12)
see "Fibonacci:" + nl
f2 = [1,1]
for nr2 = 1 to 10
see "" + f2[1] + " "
fibn(f2)
next
showarray(f2)
see " ..." + nl + nl
see "Tribonacci:" + nl
f3 = [1,1,2]
for nr3 = 1 to 9
see "" + f3[1] + " "
fibn(f3)
next
showarray(f3)
see " ..." + nl + nl
see "Tetranacci:" + nl
f4 = [1,1,2,4]
for nr4 = 1 to 8
see "" + f4[1] + " "
fibn(f4)
next
showarray(f4)
see " ..." + nl + nl
see "Lucas:" + nl
f5 = [2,1]
for nr5 = 1 to 10
see "" + f5[1] + " "
fibn(f5)
next
showarray(f5)
see " ..." + nl + nl
func fibn(fs)
s = sum(fs)
for i = 2 to len(fs)
fs[i-1] = fs[i]
next
fs[i-1] = s
return fs
func sum(arr)
sm = 0
for sn = 1 to len(arr)
sm = sm + arr[sn]
next
return sm
func showarray(fn)
svect = ""
for p = 1 to len(fn)
svect = svect + fn[p] + " "
next
see svect

View file

@ -0,0 +1,62 @@
Option Explicit
Sub Main()
Dim temp$, T() As Long, i&
'Fibonacci:
T = Fibonacci_Step(1, 15, 1)
For i = LBound(T) To UBound(T)
temp = temp & ", " & T(i)
Next
Debug.Print "Fibonacci: " & Mid(temp, 3)
temp = ""
'Tribonacci:
T = Fibonacci_Step(1, 15, 2)
For i = LBound(T) To UBound(T)
temp = temp & ", " & T(i)
Next
Debug.Print "Tribonacci: " & Mid(temp, 3)
temp = ""
'Tetranacci:
T = Fibonacci_Step(1, 15, 3)
For i = LBound(T) To UBound(T)
temp = temp & ", " & T(i)
Next
Debug.Print "Tetranacci: " & Mid(temp, 3)
temp = ""
'Lucas:
T = Fibonacci_Step(1, 15, 1, 2)
For i = LBound(T) To UBound(T)
temp = temp & ", " & T(i)
Next
Debug.Print "Lucas: " & Mid(temp, 3)
temp = ""
End Sub
Private Function Fibonacci_Step(First As Long, Count As Long, S As Long, Optional Second As Long) As Long()
Dim T() As Long, R() As Long, i As Long, Su As Long, C As Long
If Second <> 0 Then S = 1
ReDim T(1 - S To Count)
For i = LBound(T) To 0
T(i) = 0
Next i
T(1) = IIf(Second <> 0, Second, 1)
T(2) = 1
For i = 3 To Count
Su = 0
C = S + 1
Do While C >= 0
Su = Su + T(i - C)
C = C - 1
Loop
T(i) = Su
Next
ReDim R(1 To Count)
For i = 1 To Count
R(i) = T(i)
Next
Fibonacci_Step = R
End Function