Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created September 22, 2016 00:51
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/bacd321b54e83bc4bbf7bb16d2aca35c to your computer and use it in GitHub Desktop.
Save vznvzn/bacd321b54e83bc4bbf7bb16d2aca35c to your computer and use it in GitHub Desktop.
def d(s)
c = s.split('').select { |x| x == '1' }.size
d = c.to_f / s.length
return 0.5 - d
end
def f(n)
n1 = n
d2 = 0
s = ''
c = nil
while (n >= n1 && n != 1)
d = d(n.to_s(2))
c = s.length if (c.nil? && d * d2 < 0)
d2 = d
while (n.odd?)
n = (n * 3 + 1) / 2
s << '1'
end
while (n.even?)
n /= 2
s << '0'
end
end
raise if (c.nil?)
s2 = s[c..-1]
m1 = s2.split(/0+/).map { |x| x.length }.max
m0 = s2.split(/1+/).map { |x| x.length }.max
return c, m1, m0 # s
end
l = File.open('db.txt').readlines.map { |z| Kernel.eval(z) }
w = [5, 1, 7, 6]
j = 0
w.each_with_index \
{
|i, c|
a = (i - 1) * 100
b = a + 99
l2 = l[a..b].select { |x| x['cg'] > 20}.sort_by { |x| x['n'] }
l2.each \
{
|x|
n = x['n']
ns = n.to_s(2)
puts([j, x['cg'], ns.length, f(n)].join("\t"))
j += 1
}
puts
j += 20
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment