Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created March 26, 2019 02:24
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/fca37f2c17f682b67f738b735b0a724c to your computer and use it in GitHub Desktop.
Save vznvzn/fca37f2c17f682b67f738b735b0a724c to your computer and use it in GitHub Desktop.
def f2(n)
return n.odd? ? (n * 3 + 1) / 2 : n / 2
end
def count(n)
c = 0
while (n != 1)
c += n.odd? ? 1 : 0
n = f2(n)
end
return c
end
n = 2 ** 10
l = []
(n - 1).times \
{
|x|
l << [x, count(x + 1)]
}
l.sort_by! { |x| x[1] }
l.map { |x| x[0] }.each { |x| p(x) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment