Created
August 13, 2020 04:13
-
-
Save vznvzn/606de638c3354c820f9ca722c76e813a 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 f2(n) | |
return n.odd? ? (n * 3 + 1) / 2 : n / 2 | |
end | |
def seq(n) | |
l = [n] | |
while (n != 1) | |
n = f2(n) | |
l << n | |
end | |
return l | |
end | |
def count(x) | |
n = x['n'] | |
l = seq(n) | |
cg = l.index { |x| x < l[0] } | |
cg = l.size - 1 if (cg.nil?) | |
cm = (0..cg).max_by { |x| l[x] } | |
c = l.size | |
return {'n' => n, | |
'cm' => cm, | |
'cg' => cg, | |
'c' => c, | |
'k' => x['k'] | |
} | |
end | |
l = File.open('db.txt').readlines.map { |x| Kernel.eval(x) } | |
f = File.open('db5.txt', 'w') | |
l.each_with_index \ | |
{ | |
|x, i| | |
f.puts(count(x).inspect) | |
$stderr.puts(i + 1) if ((i + 1) % 100 == 0) | |
} | |
f.close | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment