81 lines
1.9 KiB
Plaintext
81 lines
1.9 KiB
Plaintext
Const As Double pp = 1.324717957244746025960908854
|
|
Const As Double ss = 1.0453567932525329623
|
|
|
|
Function padovan1(Byval n As Integer) As Integer
|
|
Dim As Integer a, b, c, d, i
|
|
a = 1: b = 1: c = 1
|
|
d = 1
|
|
For i = 1 To (n - 3)
|
|
d = a + b
|
|
a = b : b = c : c = d
|
|
Next i
|
|
Return d
|
|
End Function
|
|
|
|
Function padovan2(Byval n As Integer) As Integer
|
|
Dim As Double p = 1.0
|
|
For i As Integer = 1 To (n - 1)
|
|
p *= pp
|
|
Next i
|
|
Return Fix(p / ss)
|
|
End Function
|
|
|
|
Function padovan3(Byval n As Integer) As String
|
|
Dim As String sgte, s = "A"
|
|
Dim As Integer i, j, c
|
|
Dim As String rules(1 To 3) = {"B", "C", "AB"}
|
|
|
|
For i = 1 To n
|
|
sgte = ""
|
|
For j = 1 To Len(s)
|
|
Select Case Mid(s, j, 1)
|
|
Case "A" : c = 1
|
|
Case "B" : c = 2
|
|
Case "C" : c = 3
|
|
End Select
|
|
sgte &= rules(c)
|
|
Next j
|
|
s = sgte
|
|
Next i
|
|
Return s
|
|
End Function
|
|
|
|
Dim As Integer n
|
|
Print "First 20 terms of the Padovan sequence:"
|
|
For n = 1 To 20
|
|
Print padovan1(n); '" ";
|
|
Next
|
|
|
|
n = 1
|
|
Dim As Boolean areEqual = True
|
|
Dim As Integer list1(64), list2(64)
|
|
|
|
Do While n <= 64 And areEqual = False
|
|
list1(n) = padovan1(n)
|
|
list2(n) = padovan2(n)
|
|
If list1(n) <> list2(n) Then areEqual = False
|
|
n += 1
|
|
Loop
|
|
Print !"\nThe first 64 iterative and calculated values ";
|
|
Print Iif(areEqual, "are the same.", "differ.")
|
|
|
|
Print !"\nFirst 10 L-system strings:"
|
|
For n = 0 To 9
|
|
Print padovan3(n); " ";
|
|
Next
|
|
Print
|
|
|
|
areEqual = True
|
|
Dim As Integer list3(31)
|
|
|
|
Print !"\nLengths of the 32 first L-system strings:"
|
|
For n = 0 To 31
|
|
list3(n) = Len(padovan3(n))
|
|
Print list3(n); '" ";
|
|
If list3(n) <> list1(n) Then areEqual = False
|
|
Next
|
|
Print !"\nThese lengths are";
|
|
Print Iif(areEqual, " the 32 first terms of the Padovan sequence.", " not the 32 first terms of the Padovan sequence.")
|
|
|
|
Sleep
|