Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created June 12, 2015 02:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save vznvzn/1d32104c4190d19165d8 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby1.8
def f(n)
n1 = n
f = false
c = 0
while (n != 1)
return c if ($seen.member?(n))
$seen[n] = nil
n = (n * 3 + 1) / 2 if (n % 2 == 1)
n /= 2 while (n % 2 == 0)
f |= (n < n1)
c += 1 if (!f)
end
return c
end
$seen = {}
n = 3
cm = 0
nm = 0
loop \
{
c = f(n)
if (c > cm || n.to_s(2).length > nm) then
nm = n.to_s(2).length
cm = c if (c > cm)
p([n.to_s(2), nm, n, cm, $seen.size])
$stdout.flush
end
n += 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment