Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created January 9, 2019 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vznvzn/918659cb14d9f9e2b450487860c6e806 to your computer and use it in GitHub Desktop.
Save vznvzn/918659cb14d9f9e2b450487860c6e806 to your computer and use it in GitHub Desktop.
def f2(n)
return n.odd? ? (n * 3 + 1) / 2 : n / 2
end
def count(ns)
n1 = n = ns.to_i(2)
l1 = [n]
while (n >= n1 && n != 1)
n = f2(n)
l1 << n
end
nl = ns.length
cm = (0...l1.size).max_by { |x| l1[x] }
return {'ns' => ns,
'nl' => nl,
'cm' => cm,
'cmnl' => cm - nl}
end
def div3(n)
c = 0
while (n % 3 == 0)
n /= 3
c += 1
end
return c
end
def d3(l)
a = {}
l.each { |x| x1 = x % 3; a[x1] = a.fetch(x1, 0) + 1 }
p(a)
p(a[2].to_f / a[1])
end
l = File.open('tmp/mix30d/mixdb_cm.txt').readlines.map { |x| Kernel.eval(x) }
l.sort_by! { |x| x['cm'] }
x = l[-12]
n = n1 = x['n']
l = []
while (n >= n1)
n = f2(n)
l << n
end
cm = (0...l.size).max_by { |x| l[x] }
p([cm, l.size])
d3(l[0..cm])
d3(l[cm..-1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment