Hofstadter-Conway 10 000 sequence
class HofstadterConway10000 {
has sequence = [nil, 1, 1]
method term(n {.is_pos}) {
var a = sequence
{|i| a[i] = a[a[i-1]]+a[i-a[i-1]] } << a.len..n
a[n]
}
}
var hc = HofstadterConway10000()
var mallows = nil
for i in (1..19) {
var j = i+1
var (max_n, max_v) = (-1, -1)
for n in (1<<i .. 1<<j) {
var v = (hc.term(n) / n)
(max_n, max_v) = (n, v) if (v > max_v)
mallows = n if (v >= 0.55)
}
say ("maximum between 2^%2d and 2^%2d occurs at%7d: %.8f" % (i, j, max_n, max_v))
}
say "the mallows number is #{mallows}"Output:
Last updated
Was this helpful?