Created
August 31, 2015 18:45
-
-
Save vznvzn/cc75c46e92fb0f24ba2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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