What is the smallest Fibonacci number that is 1-9 pandigital in its first nine digits?
(In reply to
Think Big ... Think UBASIC (spoilers) by Charlie)
The program below first verifies the logarithmic formula used works for finding Fibonacci numbers, then finds the answer:
The verification of formula validity:
1 1
2 1
3 2
4 3
5 5
6 8
7 13
8 21
9 34
10 55
The answer:
2749 574.157538045026
That is, the 2749th Fibonacci number which is approximately 10^574.157538045026 or 1.437268955346967 x 10^574 is the first such number asked for.
A similar program would work for the unasked-for 10-digit pandigital.
DefDbl A-Z
Dim crlf$
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
phi = (1 + Sqr(5)) / 2
lphi = Log(phi) / Log(10)
l5 = Log(5) / Log(10)
lFib = lphi - l5 / 2
For i = 1 To 10
Text1.Text = Text1.Text & i & " " & Int(10 ^ lFib + 0.5) & crlf
lFib = lFib + lphi
Next
lFib = lphi - l5 / 2: Fibno = 1
Do
Fibno = Fibno + 1
lFib = lFib + lphi
mantissa = lFib - Int(lFib)
alog = 10 ^ mantissa
s$ = LTrim(Str(alog))
ix = InStr(s, ".")
If ix > 0 Then s = Left(s, ix - 1) + Mid(s, ix + 1)
good = 1
For i = 2 To 9
If Mid(s, i, 1) = "0" Then good = 0: Exit For
If InStr(s, Mid(s, i, 1)) < i Then good = 0: Exit For
Next
If good Then Text1.Text = Text1.Text & Fibno & " " & lFib & crlf: Exit Do
Loop
Text1.Text = Text1.Text & crlf & " done"
End Sub
|
Posted by Charlie
on 2017-08-03 11:08:15 |