67 lines
1.3 KiB
Text
67 lines
1.3 KiB
Text
' version 17-10-2016
|
|
' compile with: fbc -s console
|
|
|
|
#Define max 92 ' max for Fibonacci number
|
|
|
|
Dim Shared As ULongInt fib(max)
|
|
|
|
fib(0) = 1
|
|
fib(1) = 1
|
|
|
|
For x As Integer = 2 To max
|
|
fib(x) = fib(x-1) + fib(x-2)
|
|
Next
|
|
|
|
Function num2zeck(n As Integer) As String
|
|
|
|
If n < 0 Then
|
|
Print "Error: no negative numbers allowed"
|
|
Beep : Sleep 5000,1 : End
|
|
End If
|
|
|
|
If n < 2 Then Return Str(n)
|
|
|
|
Dim As String zeckendorf
|
|
|
|
For x As Integer = max To 1 Step -1
|
|
If fib(x) <= n Then
|
|
zeckendorf = zeckendorf + "1"
|
|
n = n - fib(x)
|
|
Else
|
|
zeckendorf = zeckendorf + "0"
|
|
End If
|
|
Next
|
|
|
|
return LTrim(zeckendorf, "0") ' get rid of leading zeroes
|
|
End Function
|
|
|
|
' ------=< MAIN >=------
|
|
|
|
Dim As Integer x, e
|
|
Dim As String zeckendorf
|
|
Print "number zeckendorf"
|
|
|
|
For x = 0 To 200000
|
|
|
|
zeckendorf = num2zeck(x)
|
|
If x <= 20 Then Print x, zeckendorf
|
|
|
|
' check for two consecutive Fibonacci numbers
|
|
If InStr(zeckendorf, "11") <> 0 Then
|
|
Print " Error: two consecutive Fibonacci numbers "; x, zeckendorf
|
|
e = e +1
|
|
End If
|
|
Next
|
|
|
|
Print
|
|
If e = 0 Then
|
|
Print " No Zeckendorf numbers with two consecutive Fibonacci numbers found"
|
|
Else
|
|
Print e; " error(s) found"
|
|
End If
|
|
|
|
' empty keyboard buffer
|
|
While Inkey <> "" : Wend
|
|
Print : Print "hit any key to end program"
|
|
Sleep
|
|
End
|