Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created December 22, 2019 21:01
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/fe3bc6d3cfb89944184bc7d2aad715e3 to your computer and use it in GitHub Desktop.
Save vznvzn/fe3bc6d3cfb89944184bc7d2aad715e3 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)
n1 = n
l = [n1]
while (n != 1)
n = f2(n)
l << n
end
return l
end
(1..2000).each \
{
|x|
ns = '1' * x
l1 = seq(ns.to_i(2))
cg = l1.index { |x| x < l1[0] }
cg = l1.size if (cg.nil?)
cm = (0...cg).max_by { |x| l1[x] }
puts([x, cm, cm - x].join("\t"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment