RosettaCodeData/Task/Hofstadter-Conway-$10,000-sequence/FutureBasic/hofstadter-conway-$10,000-sequence.futurebasic
2016-12-05 23:44:36 +01:00

46 lines
895 B
Text

include "ConsoleWindow"
// Set width of tab
def tab 9
dim as long Mallows, n, pow2, p2, pPos, uprLim
dim as double p
print
// Adjust array elements depending on size of sequence
_maxArrayElements = 1200000
input "Enter upper limit between 1 and 20 (Enter 20 gives 2^20): "; uprLim
dim as double r
dim as long a( _maxArrayElements )
if uprLim < 1 or uprLim > 20 then uprLim = 20
a(1) = 1
a(2) = 1
pow2 = 2
p2 = 2 ^ pow2
p = 0.5
pPos = 0
print
for n = 3 to 2 ^ uprLim
a(n) = a( a( n-1 ) ) + a( n-a( n-1 ) )
r = a(n) / n
if r >= 0.55 then Mallows = n
if r > p
p = r
pPos = n
end if
if n == p2
print "Maximum of a(n)/n between", " 2^"; pow2-1; " and 2^"; pow2," is "; p;, " at n = "; pPos
pow2 = pow2 + 1
p2 = 2 ^ pow2
p = 0.5
end if
next
print
print "Dr. Mallow's winning number is:"; Mallows