Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,82 @@
|
|||
' version 02-03-2019
|
||||
' compile with: fbc -s console
|
||||
|
||||
#Define max 2000
|
||||
|
||||
Dim Shared As UInteger stern(max +2)
|
||||
|
||||
Sub stern_brocot
|
||||
|
||||
stern(1) = 1
|
||||
stern(2) = 1
|
||||
|
||||
Dim As UInteger i = 2 , n = 2, ub = UBound(stern)
|
||||
|
||||
Do While i < ub
|
||||
i += 1
|
||||
stern(i) = stern(n) + stern(n -1)
|
||||
i += 1
|
||||
stern(i) = stern(n)
|
||||
n += 1
|
||||
Loop
|
||||
|
||||
End Sub
|
||||
|
||||
Function gcd(x As UInteger, y As UInteger) As UInteger
|
||||
|
||||
Dim As UInteger t
|
||||
|
||||
While y
|
||||
t = y
|
||||
y = x Mod y
|
||||
x = t
|
||||
Wend
|
||||
|
||||
Return x
|
||||
|
||||
End Function
|
||||
|
||||
' ------=< MAIN >=------
|
||||
|
||||
Dim As UInteger i
|
||||
|
||||
stern_brocot
|
||||
|
||||
Print "The first 15 are: " ;
|
||||
For i = 1 To 15
|
||||
Print stern(i); " ";
|
||||
Next
|
||||
|
||||
Print : Print
|
||||
Print " Index First nr."
|
||||
Dim As UInteger d = 1
|
||||
For i = 1 To max
|
||||
If stern(i) = d Then
|
||||
Print Using " ######"; i; stern(i)
|
||||
d += 1
|
||||
If d = 11 Then d = 100
|
||||
If d = 101 Then Exit For
|
||||
i = 0
|
||||
End If
|
||||
Next
|
||||
|
||||
Print : Print
|
||||
d = 0
|
||||
For i = 1 To 1000
|
||||
If gcd(stern(i), stern(i +1)) <> 1 Then
|
||||
d = gcd(stern(i), stern(i +1))
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
|
||||
If d = 0 Then
|
||||
Print "GCD of two consecutive members of the series up to the 1000th member is 1"
|
||||
Else
|
||||
Print "The GCD for index "; i; " and "; i +1; " = "; d
|
||||
End If
|
||||
|
||||
' empty keyboard buffer
|
||||
While Inkey <> "" : Wend
|
||||
Print : Print "hit any key to end program"
|
||||
Sleep
|
||||
End
|
||||
Loading…
Add table
Add a link
Reference in a new issue