Data type string:
original range (45) times 10.
The code is a bit longer due to string addition.
But the same in principle.
The windows console should scroll all.
Don't know about Linux though.
Code: Select all
'fibonacci by data type -- string.
'following Wiki format
'I.e.
'The first few Fibonacci numbers Fn for n = 0, 1, 2, …
'F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 F17 F18 F19 F20
'0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765
Function fibonacci(n As long) As String
static As Ubyte Qmod(0 To 19)={48,49,50,51,52,53,54,55,56,57,48,49,50,51,52,53,54,55,56,57}
static As Ubyte Qbool(0 To 19)={0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1}
Dim As Ubyte addup,addcarry
Dim As Long diff,n_,LL
if n=0 then return "0"
if n=1 or n=2 then return "1"
if n=3 then
return "2"
else
Dim As String sl="1",l="2",term
For x As long= 1 To n-3
LL=Len(l)
diff=-(LL<>Len(sl))
term="0"+l
addcarry=0
For n_=LL-1 To diff Step -1
addup=sl[n_-diff]+l[n_]-96
term[n_+1]=Qmod(addup+addcarry)
addcarry=Qbool(addup+addcarry)
Next n_
If addcarry=0 Then term=Ltrim(term,"0"):Goto skip
If n_=-1 Then term[0]=addcarry+48 :Goto skip
For n_=n_ To 0 Step -1
addup=l[n_]-48
term[n_+1]=Qmod(addup+addcarry)
addcarry=Qbool(addup+addcarry)
If addcarry=0 Then Exit For
Next n_
term[0]=addcarry+48
if addcarry=0 then term=Ltrim(term,"0")
skip:
sl=l
l=term
Next x
Function =term
end if
End Function
width 130,500
dim as string s
for n as ulong=0 to 450
s=s+ "F"&n & string(12-len(str(n))," ") &fibonacci(n) &!"\n" 'position + gap +fibonacci number + new line
'print "F";n, fibonacci(n)
next
print s
sleep