Created
September 17, 2016 01:01
-
-
Save vznvzn/061ae3ab0d7aaa9cbe1a4d516316aa45 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 f(n, w) | |
n1 = n | |
c = nil | |
l = [] | |
while (n >= n1 && n != 1) | |
l << n | |
n = n * 3 + 1 if (n.odd?) | |
if (n.even?) then | |
n /= 2 | |
c = l.size if (w == 0) | |
w -= 1 | |
end | |
end | |
return c, (0...l.size).max_by { |x| l[x] } | |
end | |
l = File.open('db.txt').readlines.map { |z| Kernel.eval(z) } | |
w = [1, 5, 6, 7] | |
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['cg'] }.reverse | |
l2.each \ | |
{ | |
|x| | |
n = x['n'] | |
ns = n.to_s(2) | |
puts([x['cg'], f(n, ns.length)].join("\t")) | |
} | |
puts | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment