Hofstadter-Conway $10,000 sequence: Difference between revisions

→‎{{header|Python}}: make this look vaguely pythonic
No edit summary
(→‎{{header|Python}}: make this look vaguely pythonic)
Line 2,184:
<lang python>from __future__ import division
 
def maxandmallows(nmaxpower2=20):
# Note: The first hc number is returned in hc[1];
# hc[0] is not part of the series.
nmax = 2**nmaxpower2
hc, mallows, mx, mxpow2 = [None, 1, 1], None, (0.5, 2), []
mxpow2 = []
mallows = None
 
# Hofstadter-Conway sequence starts at hc[1],
# hc[0] is not part of the series.
hc = [None, 1, 1]
 
for n in range(2, nmax + 1):
ratio = hc[n] / n
if ratio > mx[0]: mx = (ratio, n)
if ratio >= 0.55: mallowsmx = (ratio, n)
if ratio >= 0.55:
mallows = n
if ratio == 0.5:
print("In the region %7i < n <= %7i: max a(n)/n = %s6.4f at n = %i" %
((n)//2, n, "%6.4f at n = %i" %mx[0], mx[1]))
mxpow2.append(mx[0])
mx = (ratio, n)
hc.append(hc[hc[n]] + hc[-hc[n]])
 
return hc, mallows if mxpow2 and mxpow2[-1] < 0.55 and n > 4 else None
 
Anonymous user