Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created May 15, 2015 16:55
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/2a21ba0ec682b454372a to your computer and use it in GitHub Desktop.
Save vznvzn/2a21ba0ec682b454372a to your computer and use it in GitHub Desktop.
def f(x)
c = 0
t = x.to_s(2).length
x2 = x
l = []
while (x >= x2)
l << x.to_s(2)[0...(t-1)] if (c % (t - 1) == 0)
x = x.even? ? x / 2 : x * 3 + 1
c += 1
end
return l
end
p = ARGV[0].to_i
n = 2 ** p + 1
s1 = n.to_s(2).length
l2 = []
loop \
{
break if (n.to_s(2).length != s1)
l = f(n)
if (l.size > 1) then
l.each { |x| p(x.to_i(2)) }
end
n += 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment