Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created July 23, 2015 16:49
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/0ee5c7845bfb5ea6871e to your computer and use it in GitHub Desktop.
Save vznvzn/0ee5c7845bfb5ea6871e to your computer and use it in GitHub Desktop.
def run(p)
n = 2 ** p - 1
n1 = n
mw = nil
fw = fg = true
c = cg = cw = 0
mn = [0, 0]
while (n > 1)
n = n * 3 + 1
n /= 2 while (n.even?)
ns = n.to_s(2)
if (fw) then
l = ns.split(/0+/)
w = l[-1].length
mw = mw.nil? ? w : [mw, w].min
cw = c
fw = false if (w > mw)
end
if (fg) then
cg = c
fg = false if (n < n1)
end
mn = [mn, [n, c]].max
c += 1
end
puts([cw, mn[1], cg, c].join("\t"))
$stdout.flush
end
1000.times { |p| run(p) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment