Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created August 13, 2020 04:13
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/606de638c3354c820f9ca722c76e813a to your computer and use it in GitHub Desktop.
Save vznvzn/606de638c3354c820f9ca722c76e813a to your computer and use it in GitHub Desktop.
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