Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created September 10, 2016 00:34
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/b2540a44e6e2a5df57064ad430c6367c to your computer and use it in GitHub Desktop.
Save vznvzn/b2540a44e6e2a5df57064ad430c6367c to your computer and use it in GitHub Desktop.
def f1(n)
n = (n * 3 + 1) / 2 while (n % 2 == 1)
n /= 2 while (n % 2 == 0)
return n
end
def dense(s)
c = 0
s.length.times { |i| c += s[i, 1].to_i }
return c.to_f / s.length
end
l = File.open('db.txt').readlines.map { |z| Kernel.eval(z) }
w = [1, 5, 6, 7]
j = 0
w.each_with_index \
{
|i, c|
a = (i - 1) * 100
b = a + 99
l2 = l[a..b].sort_by { |x| x['cg'] }.reverse
5.times \
{
|i|
n = l2[i]['n']
n1 = n
t = 0
ns1 = n.to_s(2).length
while (n >= n1 && n != 1)
n = f1(n)
ns = n.to_s(2)
w = ns.length / 2
dlo = dense(ns[0...w])
dhi = dense(ns[w..-1])
d = dlo - dhi
t += d
puts([j, c, ns.length - ns1, dense(ns), dlo, dhi, t].join("\t"))
j += 1
end
j += 50
puts
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment