Created
September 10, 2016 00:34
-
-
Save vznvzn/b2540a44e6e2a5df57064ad430c6367c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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