Anonymous user
Hofstadter-Conway $10,000 sequence: Difference between revisions
Hofstadter-Conway $10,000 sequence (view source)
Revision as of 16:12, 18 December 2016
, 7 years ago→{{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
# hc[0] is not part of the series.▼
nmax = 2**nmaxpower2
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]:
if ratio >= 0.55:
mallows = n
if ratio == 0.5:
print("In the region %7i < n <= %7i: max a(n)/n = %
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
|