Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created September 1, 2016 00:56
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/7f487a8bf906f9c9f4b7b0c911c1a81e to your computer and use it in GitHub Desktop.
Save vznvzn/7f487a8bf906f9c9f4b7b0c911c1a81e to your computer and use it in GitHub Desktop.
def f1(n)
n = (n * 3 + 1) / 2 while (n % 2 == 1)
n /= 2 while (n % 2 == 0)
return n
end
def seq2(n)
l = [n]
n1 = n
l << (n = f1(n)) while (n >= n1 && n != 1)
return l
end
l = File.open('grow.txt').readlines
l[-10..-1].each\
{
|x|
l1 = Kernel.eval(x)
l1.each \
{
|z|
n = z['n']
l2 = seq2(n).map { |x| x.to_s(2).length }
l2.each_with_index { |x, i| puts([i, x - l2[0]].join("\t")) }
puts
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment