Hofstadter-Conway $10,000 sequence: Difference between revisions
Content deleted Content added
PatGarrett (talk | contribs) |
No edit summary |
||
Line 1,251: | Line 1,251: | ||
Maximum in 524288..1048576 is 0.533779 |
Maximum in 524288..1048576 is 0.533779 |
||
Mallows number is 1489</pre> |
Mallows number is 1489</pre> |
||
=={{header|FutureBasic}== |
|||
<lang futurebasic> |
|||
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 "Mallows number is:"; Mallows |
|||
</lang> |
|||
Output: |
|||
<pre> |
|||
Enter upper limit between 1 and 20 (Enter 20 gives 2^20): 20 |
|||
Maximum of a(n)/n between 2^ 1 and 2^ 2 is 0.6666666667 at n = 3 |
|||
Maximum of a(n)/n between 2^ 2 and 2^ 3 is 0.6666666667 at n = 6 |
|||
Maximum of a(n)/n between 2^ 3 and 2^ 4 is 0.6363636364 at n = 11 |
|||
Maximum of a(n)/n between 2^ 4 and 2^ 5 is 0.6086956522 at n = 23 |
|||
Maximum of a(n)/n between 2^ 5 and 2^ 6 is 0.5909090909 at n = 44 |
|||
Maximum of a(n)/n between 2^ 6 and 2^ 7 is 0.5760869565 at n = 92 |
|||
Maximum of a(n)/n between 2^ 7 and 2^ 8 is 0.5674157303 at n = 178 |
|||
Maximum of a(n)/n between 2^ 8 and 2^ 9 is 0.5594594595 at n = 370 |
|||
Maximum of a(n)/n between 2^ 9 and 2^ 10 is 0.5549374131 at n = 719 |
|||
Maximum of a(n)/n between 2^ 10 and 2^ 11 is 0.5501008742 at n = 1487 |
|||
Maximum of a(n)/n between 2^ 11 and 2^ 12 is 0.5474628926 at n = 2897 |
|||
Maximum of a(n)/n between 2^ 12 and 2^ 13 is 0.5441447479 at n = 5969 |
|||
Maximum of a(n)/n between 2^ 13 and 2^ 14 is 0.5424427088 at n = 11651 |
|||
Maximum of a(n)/n between 2^ 14 and 2^ 15 is 0.5400710975 at n = 22223 |
|||
Maximum of a(n)/n between 2^ 15 and 2^ 16 is 0.5387840206 at n = 45083 |
|||
Maximum of a(n)/n between 2^ 16 and 2^ 17 is 0.537043657 at n = 89516 |
|||
Maximum of a(n)/n between 2^ 17 and 2^ 18 is 0.5360200678 at n = 181385 |
|||
Maximum of a(n)/n between 2^ 18 and 2^ 19 is 0.5346454311 at n = 353683 |
|||
Maximum of a(n)/n between 2^ 19 and 2^ 20 is 0.53377923 at n = 722589 |
|||
Mallows number is: 1489 |
|||
</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |