Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created August 31, 2015 18:45
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/cc75c46e92fb0f24ba2e to your computer and use it in GitHub Desktop.
Save vznvzn/cc75c46e92fb0f24ba2e to your computer and use it in GitHub Desktop.
def f(n, seen)
n1 = n
while (n >= n1)
if (!seen[n].nil?) then
raise if (n1 < seen[n])
else
seen[n] = n1
end
n = n * 3 + 1 if (n.odd?)
n /= 2 while (n.even?)
end
end
seen = {}
n = 3
2000.times \
{
f(n, seen)
n += 2
}
seen.to_a.each { |x, y| puts([x, y].join("\t")) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment