We were just off by a few 0.7e21 :P
3,311,648,143,516,982,017,180,081
We were just off by a few 0.7e21 :P
3,311,648,143,516,982,017,180,081
5,358,359,254,990,966,640,871,840
8,670,007,398,507,948,658,051,921
14,028,366,653,498,915,298,923,761
I wonder how many characters a single post can contain.
22,698,374,052,006,863,956,975,682
36,726,740,705,505,779,255,899,443
59,425,114,757,512,643,212,875,125
144
96,151,855,463,018,422,468,774,568
155,576,970,220,531,065,681,649,693
251,728,825,683,549,488,150,424,261
407,305,795,904,080,553,832,073,954
659,034,621,587,630,041,982,498,215
1,066,340,417,491,710,595,814,572,169
1,725,375,039,079,340,637,797,070,384
And now, for the cheating:
Dim As String Fib1, Fib2, FibResult, FibFormatted
Dim As Integer L1, L2, i, j, q, FibRange, m1, m2, CarryFlag, answer
Input "Input the number of Fibonacci numbers to generate (press Enter when done):", FibRange
If FibRange < 1 Or FibRange > 1000 Then
Print "Please enter a number from 1 to 1000."
End
EndIf
Fib1 = "1"
Fib2 = "1"
Print "1: 1"
Print "2: 1"
For i = 1 To FibRange
L1 = LEN(Fib1)
L2 = Len(Fib2)
For j = L1 TO 1 Step -1
m1 = Cast(Integer, Mid(Fib1, j, 1))
m2 = Cast(Integer, Mid(Fib2, j + (Len(Fib2) - Len(Fib1)), 1))
m2 = m2 + m1
IF CarryFlag = 1 THEN
m2 = m2 + 1
CarryFlag = 0
END IF
IF m2 >= 10 Then
m2 = m2 - 10
CarryFlag = 1
END IF
FibResult = Str(m2) + FibResult
NEXT j
If CarryFlag = 1 Then
If L1 = L2 Then
FibResult = "1" + FibResult
Else
m2 = Cast(Integer, Mid(Fib2, 1, 1)) + 1
FibResult = Str(m2) + FibResult
EndIf
CarryFlag = 0
Else
If L1 <> L2 Then
m2 = Cast(Integer, Mid(Fib2, 1, 1))
fibResult = Str(m2) + FibResult
EndIf
EndIf
If Len(FibResult) > 3 Then
q = Len(FibResult) Mod 3
For j = Len(FibResult) To q Step -3
FibFormatted = Mid(FibResult, j - 2, 3) + FibFormatted
If j > q Then
FibFormatted = "," + FibFormatted
EndIf
Next j
Else
q = Len(FibResult)
EndIf
FibFormatted = Mid(FibResult, 1, q) + FibFormatted
If Left(FibFormatted,1) = "," Then
FibFormatted = Right(FibFormatted, Len(FibFormatted) - 1)
EndIf
Print Str(i + 2); ": "; FibFormatted
Fib1 = Fib2
Fib2 = FibResult
FibResult = ""
FibFormatted = ""
Next i
Compiled with FreeBASIC using FbEdit IDE. Whee!
Hi BitBlt,
May i know what are you doing?
Oh, I was looking at the posts, and noticed that Momerath asked "I wonder how many characters a single post can contain?". I got to thinking that since there's a limit to how many digits the numeric datatypes of some programming languages can contain, how would I go about writing a generalized Fibonacci number generator that wasn't constrained by that limit?
The post I made was one such program. It uses string datatypes, and manipulates each digit independently. It is only limited by the possible length of the "string" datatype for this language (I think it's 32767...I'd have to check). So in theory, it could generate all Fibonacci numbers with 32767 or fewer digits. It uses basically the same technique of the "carry flag" that Assembler uses for register arithmetic.
Does it wreck the posting game? No, not really. I posted the next few numbers in the series on my earlier post, but I did indicate that I had cheated. And I thought that it was a programming technique that was worth sharing...sorry if anyone was offended.
oh i see. But this game is getting harder to play as the number increase